From 40a42476118827af332e98c707765f5cb97d9aa1 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 25 Nov 2015 07:44:32 -0500 Subject: [PATCH] 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 --- lib/ansible/modules/extras/system/puppet.py | 32 +++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/extras/system/puppet.py b/lib/ansible/modules/extras/system/puppet.py index 3a3fb6e3544..98b09bb3f90 100644 --- a/lib/ansible/modules/extras/system/puppet.py +++ b/lib/ansible/modules/extras/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: