diff --git a/library/puppet b/library/puppet index 9c2149e..51464ca 100644 --- a/library/puppet +++ b/library/puppet @@ -67,6 +67,12 @@ options: - Puppet environment to be used. required: false default: None + logdest: + description: + - Where the puppet logs should go, if puppet apply is being used + required: false + default: stdout + choices: [ 'stdout', 'syslog' ] requirements: [ puppet ] author: "Monty Taylor (@emonty)" ''' @@ -111,8 +117,12 @@ def main(): timeout=dict(default="30m"), puppetmaster=dict(required=False, default=None), manifest=dict(required=False, default=None), + logdest=dict( + required=False, default=['stdout'], + choices=['stdout', 'syslog']), show_diff=dict( - default=False, aliases=['show-diff'], type='bool'), # internal code to work with --diff, do not use + # internal code to work with --diff, do not use + default=False, aliases=['show-diff'], type='bool'), facts=dict(default=None), facter_basename=dict(default='ansible'), environment=dict(required=False, default=None), @@ -183,7 +193,9 @@ def main(): else: cmd += " --no-noop" else: - cmd = "%s apply --detailed-exitcodes --logdest syslog " % base_cmd + cmd = "%s apply --detailed-exitcodes " % base_cmd + if p['logdest'] == 'syslog': + cmd += "--logdest syslog " if p['environment']: cmd += "--environment '%s' " % p['environment'] if module.check_mode: @@ -195,7 +207,7 @@ def main(): if rc == 0: # success - module.exit_json(rc=rc, changed=False) + module.exit_json(rc=rc, changed=False, stdout=stdout) elif rc == 1: # rc==1 could be because it's disabled # rc==1 could also mean there was a compilation failure @@ -206,18 +218,19 @@ def main(): msg = "puppet did not run" module.exit_json( rc=rc, disabled=disabled, msg=msg, - error=True) + error=True, stdout=stdout, stderr=stderr) elif rc == 2: # success with changes - module.exit_json(rc=0, changed=True) + module.exit_json(rc=0, changed=True, stdout=stdout, stderr=stderr) elif rc == 124: # timeout module.exit_json( - rc=rc, msg="%s timed out" % cmd) + rc=rc, msg="%s timed out" % cmd, stdout=stdout, stderr=stderr) else: # failure module.fail_json( - rc=rc, msg="%s failed with return code: %d" % (cmd, rc)) + rc=rc, msg="%s failed with return code: %d" % (cmd, rc), + stdout=stdout, stderr=stderr) # import module snippets from ansible.module_utils.basic import * diff --git a/tasks/main.yml b/tasks/main.yml index 339c957..2c00eab 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -57,6 +57,7 @@ show_diff: "{{ show_diff|default(false) }}" facts: "{{ facts|default(omit) }}" facter_basename: "{{ facter_basename|default(omit) }}" + logdest: "{{ puppet_logdest|default(omit) }}" - block: - name: find logs