Repository: ansible/ansible

Issue:
win_chocolatey missing functionality
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
win_chocolatey

##### ANSIBLE VERSION
```
2.3.0.0
```

##### CONFIGURATION
None

##### OS / ENVIRONMENT
<!---
The ansible server is centos 6.7, managing windows server 12, 8 and windows 7 environment.
-->

##### SUMMARY
I would like to run the chocolatey uninstaller with the '-n' or '--skip-powershell' flag. But more generally, there is no way to pass arguments to chocolatey. There is only params and installer_args which do not accomplish the job. 

##### STEPS TO REPRODUCE
    - name: Update java
       win_chocolatey:
          name: java
          version: '8.31'
          state: absent
          choco_args: -n -i 


##### EXPECTED RESULTS
To uninatall version 8.31 of java using the native uninstaller, and not the chocolateyuninstall.ps1 script. 

##### ACTUAL RESULTS
Considering that 'choco_args' is not an available parameter, it simply errors out complaining of unknown syntax. 




Discussion:
cc @smadam813 @nitzmahone
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
discussed at windows sprint 1.

sprint plan was to tackle bug fixes, rather than features.

needs_contributor
Rather than allowing for additional arbitrary options, I would rather add parameters for those options that make sense to use with **win_chocolatey**. So that we can control whether these are added to install, upgrade or uninstall commands. And to ensure they don't cause expected failures we get support tickets for.
There are over 50 flags for installations alone. I don't think it is realistic to have parameters for each flag for each operation... If it fails it is on the user for an incorrect flag.
@nmulvihill We don't necessarily need a parameter for each flag. Sensible choices can be made.

We have experience with modules that doe have `extra_opts` and in every case we have regretted this decision afterwards.

Resolving patch:
diff --git a/lib/ansible/modules/windows/win_chocolatey.py b/lib/ansible/modules/windows/win_chocolatey.py
--- a/lib/ansible/modules/windows/win_chocolatey.py
+++ b/lib/ansible/modules/windows/win_chocolatey.py
@@ -25,7 +25,6 @@
                     'status': ['preview'],
                     'supported_by': 'curated'}
 
-
 DOCUMENTATION = r'''
 ---
 module: win_chocolatey
@@ -34,41 +33,37 @@
 description:
     - Installs packages using Chocolatey (U(http://chocolatey.org/)).
     - If Chocolatey is missing from the system, the module will install it.
-    - List of packages can be found at U(http://chocolatey.org/packages)
+    - List of packages can be found at U(http://chocolatey.org/packages).
 options:
   name:
     description:
       - Name of the package to be installed.
-    required: true
+    required: yes
   state:
     description:
       - State of the package on the system.
     choices:
-      - present
       - absent
       - latest
+      - present
       - reinstalled
     default: present
   force:
     description:
       - Forces install of the package (even if it already exists).
       - Using C(force) will cause ansible to always report that a change was made.
-    choices:
-      - yes
-      - no
-    default: no
+    type: bool
+    default: 'no'
   upgrade:
     description:
       - If package is already installed it, try to upgrade to the latest version or to the specified version.
-      - As of Ansible v2.3 this is deprecated, set parameter C(state) to "latest" for the same result.
-    choices:
-      - yes
-      - no
-    default: no
+      - As of Ansible v2.3 this is deprecated, set parameter C(state) to C(latest) for the same result.
+    type: bool
+    default: 'no'
   version:
     description:
       - Specific version of the package to be installed.
-      - Ignored when C(state) is set to "absent".
+      - Ignored when C(state) is set to C(absent).
   source:
     description:
       - Specify source rather than using default chocolatey repository.
@@ -83,17 +78,20 @@
   allow_empty_checksums:
     description:
       - Allow empty checksums to be used.
-    default: false
+    type: bool
+    default: 'no'
     version_added: '2.2'
   ignore_checksums:
     description:
       - Ignore checksums altogether.
-    default: false
+    type: bool
+    default: 'no'
     version_added: '2.2'
   ignore_dependencies:
     description:
       - Ignore dependencies, only install/upgrade the package itself.
-    default: false
+    type: bool
+    default: 'no'
     version_added: '2.1'
   timeout:
     description:
@@ -101,36 +99,51 @@
     default: 2700
     version_added: '2.3'
     aliases: [ execution_timeout ]
-author: "Trond Hindenes (@trondhindenes), Peter Mounce (@petemounce), Pepe Barbe (@elventear), Adam Keech (@smadam813)"
+  skip_scripts:
+    description:
+    - Do not run I(chocolateyInstall.ps1) or I(chocolateyUninstall.ps1) scripts.
+    type: bool
+    default: 'no'
+    version_added: '2.4'
+notes:
+- Provide the C(version) parameter value as a string (e.g. C('6.1')), otherwise it
+  is considered to be a floating-point number and depending on the locale could
+  become C(6,1), which will cause a failure.
+author:
+- Trond Hindenes (@trondhindenes)
+- Peter Mounce (@petemounce)
+- Pepe Barbe (@elventear)
+- Adam Keech (@smadam813)
 '''
 
 # TODO:
 # * Better parsing when a package has dependencies - currently fails
 # * Time each item that is run
 # * Support 'changed' with gems - would require shelling out to `gem list` first and parsing, kinda defeating the point of using chocolatey.
+# * Version provided not as string might be translated to 6,6 depending on Locale (results in errors)
 
 EXAMPLES = r'''
-  # Install git
+- name: Install git
   win_chocolatey:
     name: git
     state: present
 
-  # Upgrade installed packages
+- name: Upgrade installed packages
   win_chocolatey:
     name: all
     state: latest
 
-  # Install notepadplusplus version 6.6
+- name: Install notepadplusplus version 6.6
   win_chocolatey:
     name: notepadplusplus.install
     version: '6.6'
 
-  # Install git from specified repository
+- name: Install git from specified repository
   win_chocolatey:
     name: git
     source: https://someserver/api/v2/
 
-  # Uninstall git
+- name: Uninstall git
   win_chocolatey:
     name: git
     state: absent


Test patch: