summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-11-25 07:44:32 -0500
committerMonty Taylor <mordred@inaugust.com>2015-12-14 23:40:01 -0500
commit6912ca0acaed0d738d8dd9867721d2ff0094084a (patch)
tree25a1b7fb743993ac88e89dfc82144c22e9c7a19b
parentd6a976f90cf63454e5751cfde899a4df2b0eee33 (diff)
downloadansible-modules-extras-6912ca0acaed0d738d8dd9867721d2ff0094084a.tar.gz
Sync minor fixes from OpenStack Infra
Infra has been keeping a local copy of this waiting for ansible 2 to release. In getting ready for ansible 2 (and our ability to delete our local copy of the file, I noticed we had a couple of minor cleanups. Also, the timeout command is there to improve life and workaround puppet deficiencies. However, it's not working around deficiencies on systems that do not have the timeout command if we blindly use it. The puppet specific timeout options are more complex and out of scope of this. Issue: #1273
-rw-r--r--system/puppet.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/system/puppet.py b/system/puppet.py
index 3a3fb6e3..98b09bb3 100644
--- a/system/puppet.py
+++ b/system/puppet.py
@@ -19,6 +19,11 @@ import os
import pipes
import stat
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
DOCUMENTATION = '''
---
module: puppet
@@ -38,13 +43,15 @@ options:
required: false
default: None
manifest:
- desciption:
+ description:
- Path to the manifest file to run puppet apply on.
required: false
default: None
show_diff:
description:
- - Should puppet return diffs of changes applied. Defaults to off to avoid leaking secret changes by default.
+ - >
+ Should puppet return diffs of changes applied. Defaults to off to
+ avoid leaking secret changes by default.
required: false
default: no
choices: [ "yes", "no" ]
@@ -127,6 +134,9 @@ def main():
module.fail_json(
msg="Could not find puppet. Please ensure it is installed.")
+ global TIMEOUT_CMD
+ TIMEOUT_CMD = module.get_bin_path("timeout", False)
+
if p['manifest']:
if not os.path.exists(p['manifest']):
module.fail_json(
@@ -139,7 +149,8 @@ def main():
PUPPET_CMD + " config print agent_disabled_lockfile")
if os.path.exists(stdout.strip()):
module.fail_json(
- msg="Puppet agent is administratively disabled.", disabled=True)
+ msg="Puppet agent is administratively disabled.",
+ disabled=True)
elif rc != 0:
module.fail_json(
msg="Puppet agent state could not be determined.")
@@ -150,19 +161,24 @@ def main():
module.params['facter_basename'],
module.params['facts'])
- base_cmd = "timeout -s 9 %(timeout)s %(puppet_cmd)s" % dict(
- timeout=pipes.quote(p['timeout']), puppet_cmd=PUPPET_CMD)
+ if TIMEOUT_CMD:
+ base_cmd = "%(timeout_cmd)s -s 9 %(timeout)s %(puppet_cmd)s" % dict(
+ timeout_cmd=TIMEOUT_CMD,
+ timeout=pipes.quote(p['timeout']),
+ puppet_cmd=PUPPET_CMD)
+ else:
+ base_cmd = PUPPET_CMD
if not p['manifest']:
cmd = ("%(base_cmd)s agent --onetime"
- " --ignorecache --no-daemonize --no-usecacheonfailure --no-splay"
- " --detailed-exitcodes --verbose") % dict(
+ " --ignorecache --no-daemonize --no-usecacheonfailure"
+ " --no-splay --detailed-exitcodes --verbose") % dict(
base_cmd=base_cmd,
)
if p['puppetmaster']:
cmd += " --server %s" % pipes.quote(p['puppetmaster'])
if p['show_diff']:
- cmd += " --show_diff"
+ cmd += " --show-diff"
if p['environment']:
cmd += " --environment '%s'" % p['environment']
if module.check_mode: