Make puppet logout destination configurable
So that we can upstream this, make the log output from the puppet command configurable with a default value being what it was for us before. As part of that, restore returning stdout and stderr even though they'll be empty. Depends-On: I22b1d0e1fb635f2c626d75a11764725c8753bf24 Change-Id: I245ac8c3533cce4a598909c03e1f2ba0f7b06850
This commit is contained in:
parent
403d157c45
commit
d028a88572
@ -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 *
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user