Repository: ansible/ansible
Pull request: Add additional puppet options
Add support for puppet options --debug, --verbose, --summary,
and extend logdest to support logging to stdout and syslog at
the same time.

Fixes #37986

##### SUMMARY
Add support for additional puppet output options; --debug, --verbose, --summary.

Also extends 'logdest' to support multiple log destinations as puppet cli accepts multiple --logdest args.

##### ISSUE TYPE
 - Feature Pull Request

##### COMPONENT NAME
puppet module

##### ANSIBLE VERSION
ansible 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/stack/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]


##### ADDITIONAL INFORMATION
Notably, this change will allow OpenStack TripleO to replace existing puppet tasks currently run via the command module with tasks using the puppet module, and have better check mode support.  lp:1779408

Problem statement:
The puppet module should support a parameter to enable --debug mode during the puppet run
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
Always add information AFTER of these html comments.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->

 - Feature Idea

##### COMPONENT NAME
<!---
Insert below this comment the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
puppet

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

```

##### SUMMARY
<!--- Explain the problem briefly -->
The puppet ansible module should also enable a parameter which can turn on debug mode. 

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

There are times when you want to see the output of the puppet run on the target server while ansible is running puppet through the puppet module. There is no way currently you can do that as that parameter is not supported by the ansible puppet module.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
There is no parameter to enable the debug mode. 
```

Hints from issue discussion:
Files identified in the description:
* [lib/ansible/modules/system/puppet.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/puppet.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @emonty @nibalizer
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Or it should just activate it when ansible itself is in debug mode.
bcoca, 
Not really. I'd like to see a parameter to the module itself, which, if enabled will run puppet on the target node with --debug switch on.

Commit message: Fix silly yaml error

Patch to review:
diff --git a/changelogs/fragments/puppet_debugging_options.yaml b/changelogs/fragments/puppet_debugging_options.yaml
new file mode 100644
index 00000000000000..588063aff9e2b0
--- /dev/null
+++ b/changelogs/fragments/puppet_debugging_options.yaml
@@ -0,0 +1,4 @@
+---
+features:
+  - Add support for --debug, --verbose, --summarize
+  - Add support for setting logdest to both stdout and syslog via 'all'
diff --git a/lib/ansible/modules/system/puppet.py b/lib/ansible/modules/system/puppet.py
index a54c65f06d117a..ec558b2038228e 100644
--- a/lib/ansible/modules/system/puppet.py
+++ b/lib/ansible/modules/system/puppet.py
@@ -43,9 +43,10 @@
     description:
       - Puppet environment to be used.
   logdest:
-    description:
-      - Where the puppet logs should go, if puppet apply is being used.
-    choices: [ stdout, syslog ]
+    description: |
+      Where the puppet logs should go, if puppet apply is being used. 'all' 
+      will go to both stdout and syslog.
+    choices: [ stdout, syslog, all ]
     default: stdout
     version_added: "2.1"
   certname:
@@ -61,6 +62,18 @@
       - Execute a specific piece of Puppet code.
       - It has no effect with a puppetmaster.
     version_added: "2.1"
+  summarize:
+    description:
+      - Whether to print a transaction summary
+    version_added: "2.7"
+  verbose:
+    description:
+      - Print extra information
+    version_added: "2.7"
+  debug:
+    description:
+      - Enable full debugging
+    version_added: "2.7"
 requirements:
 - puppet
 author:
@@ -90,6 +103,12 @@
 - name: Run puppet using a specific tags
   puppet:
     tags: update,nginx
+
+- name: Run a manifest with debug, log to both syslog and stdout, specify module path
+  puppet:
+    modulepath: /etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules
+    logdest: all
+    manifest: /var/lib/example/puppet_step_config.pp
 '''
 
 import json
@@ -129,7 +148,9 @@ def main():
             puppetmaster=dict(type='str'),
             modulepath=dict(type='str'),
             manifest=dict(type='str'),
-            logdest=dict(type='str', default='stdout', choices=['stdout', 'syslog']),
+            logdest=dict(type='str', default='stdout', choices=['stdout',
+                                                                'syslog',
+                                                                'all']),
             # internal code to work with --diff, do not use
             show_diff=dict(type='bool', default=False, aliases=['show-diff']),
             facts=dict(type='dict'),
@@ -138,6 +159,9 @@ def main():
             certname=dict(type='str'),
             tags=dict(type='list'),
             execute=dict(type='str'),
+            summarize=dict(type='bool', default=False),
+            debug=dict(type='bool', default=False),
+            verbose=dict(type='bool', default=False),
         ),
         supports_check_mode=True,
         mutually_exclusive=[
@@ -212,6 +236,8 @@ def main():
         cmd = "%s apply --detailed-exitcodes " % base_cmd
         if p['logdest'] == 'syslog':
             cmd += "--logdest syslog "
+        if p['logdest'] == 'all':
+            cmd += " --logdest syslog --logdest stdout"
         if p['modulepath']:
             cmd += "--modulepath='%s'" % p['modulepath']
         if p['environment']:
@@ -228,6 +254,12 @@ def main():
             cmd += " --execute '%s'" % p['execute']
         else:
             cmd += pipes.quote(p['manifest'])
+        if p['summarize']:
+            cmd += " --summarize"
+        if p['debug']:
+            cmd += " --debug"
+        if p['verbose']:
+            cmd += " --verbose"
     rc, stdout, stderr = module.run_command(cmd)
 
     if rc == 0:


Code review comments:
diff_hunk: @@ -0,0 +1,4 @@
+---
+features:
path: changelogs/fragments/puppet_debugging_options.yaml
text: @user1:
Use `minor_changes`.