Add support for check mode

This commit is contained in:
Monty Taylor 2015-05-29 07:06:15 -04:00
parent 1605b1ec9c
commit 12c945388b

View file

@ -99,6 +99,7 @@ def main():
facts=dict(default=None), facts=dict(default=None),
facter_basename=dict(default='ansible'), facter_basename=dict(default='ansible'),
), ),
supports_check_mode=True,
required_one_of=[ required_one_of=[
('puppetmaster', 'manifest'), ('puppetmaster', 'manifest'),
], ],
@ -129,7 +130,7 @@ def main():
module.fail_json( module.fail_json(
msg="Puppet agent state could not be determined.") msg="Puppet agent state could not be determined.")
if module.params['facts']: if module.params['facts'] and not module.check_mode:
_write_structured_data( _write_structured_data(
_get_facter_dir(), _get_facter_dir(),
module.params['facter_basename'], module.params['facter_basename'],
@ -139,7 +140,7 @@ def main():
timeout=pipes.quote(p['timeout']), puppet_cmd=PUPPET_CMD) timeout=pipes.quote(p['timeout']), puppet_cmd=PUPPET_CMD)
if p['puppetmaster']: if p['puppetmaster']:
cmd = ("%(base_cmd) agent --onetime" cmd = ("%(base_cmd)s agent --onetime"
" --server %(puppetmaster)s" " --server %(puppetmaster)s"
" --ignorecache --no-daemonize --no-usecacheonfailure --no-splay" " --ignorecache --no-daemonize --no-usecacheonfailure --no-splay"
" --detailed-exitcodes --verbose") % dict( " --detailed-exitcodes --verbose") % dict(
@ -147,10 +148,13 @@ def main():
puppetmaster=pipes.quote(p['puppetmaster'])) puppetmaster=pipes.quote(p['puppetmaster']))
if p['show_diff']: if p['show_diff']:
cmd += " --show-diff" cmd += " --show-diff"
if module.check_mode:
cmd += " --noop"
else: else:
cmd = ("%(base_cmd) apply --detailed-exitcodes %(manifest)s" % dict( cmd = "%s apply --detailed-exitcodes " % base_cmd
base_cmd=base_cmd, if module.check_mode:
manifest=pipes.quote(p['manifest']))) cmd += "--noop "
cmd += pipes.quote(p['manifest'])
rc, stdout, stderr = module.run_command(cmd) rc, stdout, stderr = module.run_command(cmd)
if rc == 0: if rc == 0: