Repository: ansible/ansible

Issue:
win_chocolatey: Installing latest prerelease packages not implementet? 

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
`win_chocolatey`

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
```
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/ubuntu/vault.txt
HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False
```

##### OS / ENVIRONMENT
From Ubuntu 17.04
Against Windows Server 2012R2

##### SUMMARY
I can't find any way to install the *latest* prerelease of a Chocolatey package without setting the version for the package explicit. In the Chocolatey CLI this is done with a `--pre` or `--prerelease` flag. 
The args that are available in the module is `install_args` and `params`, none of them can take `--pre` as an argument. I guess `prerelease: yes` in combination with `state: latest` must be implemented to do what I want. The case comes when we are developing new tools and want to test them out as prerelease packages before bumping to stable. 

##### STEPS TO REPRODUCE
Have a Chocolatey package on a feed, only available as prerelease (no stable yet). 

<!--- Paste example playbooks or commands between quotes below -->
```yaml

- name: Install SomeTool
     win_chocolatey: name=SomeTool source="{{ InternalSoftwareChocoFeed }}" state=latest
     tags: SomeTool
```

OR 

```yaml
- name: Install SomeTool
     win_chocolatey: name=SomeTool source="{{ InternalSoftwareChocoFeed }}" state=latest install_args="--pre"
     tags: SomeTool
```

##### EXPECTED RESULTS
Install latest prerelease package if some flag is given. 

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
fatal: [SomeServer]: FAILED! => {
    "changed": false,
    "choco_error_cmd": "choco.exe install -v --no-progress -y SomeTool --timeout 2700 --failonunfound --source SomeFeed --installargs --pre",
    "choco_error_log": [
        "Chocolatey v0.10.7",
        "Installing the following packages:",
        "SomeTool",
        "By installing you accept licenses for the packages.",
        "SomeTool not installed. The package was not found with the source(s) listed.",
        " If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.",
        " Version: \"\"",
        " Source(s): \"SomeFeed\"",
        "",
        "Chocolatey installed 0/1 packages. 1 packages failed.",
        " See the log for details (C:\\ProgramData\\chocolatey\\logs\\chocolatey.log).",
        "",
        "Failures",
        " - SomeTool - SomeTool not installed. The package was not found with the source(s) listed.",

        " If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.",
        " Version: \"\"",
        " Source(s): \"SomeFeed\""
    ],
    "command": "choco.exe install -v --no-progress -y SomeTool --timeout 2700 --failonunfound --source SomeFeed --installargs --pre",
    "failed": true,
    "msg": "Error installing package 'SomeTool'",
    "rc": 1,
    "stdout": "Chocolatey v0.10.7\r\nInstalling the following packages:\r\nSomeTool\r\nBy installing you accept licenses for the packages.\r\nSomeTool not installed. The package was not found with the source(s) listed.\r\n If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.\r\n Version: \"\"\r\n Source(s): \"SomeFeed\"\r\n\r\nChocolatey installed 0/1 packages. 1 packages failed.\r\n See the log for details (C:\\ProgramData\\chocolatey\\logs\\chocolatey.log).\r\n\r\nFailures\r\n - SomeTool - SomeTool not installed. The package was not found with the source(s) listed.\r\n If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.\r\n Version: \"\"\r\n Source(s): \"SomeFeed\"\r\n",
    "stdout_lines": [
        "Chocolatey v0.10.7",
        "Installing the following packages:",
        "SomeTool",
        "By installing you accept licenses for the packages.",
        "SomeTool not installed. The package was not found with the source(s) listed.",
        " If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.",
        " Version: \"\"",
        " Source(s): \"SomeFeed\"",
        "",
        "Chocolatey installed 0/1 packages. 1 packages failed.",
        " See the log for details (C:\\ProgramData\\chocolatey\\logs\\chocolatey.log).",
        "",
        "Failures",
        " - SomeTool - SomeTool not installed. The package was not found with the source(s) listed.",

        " If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.",
        " Version: \"\"",
        " Source(s): \"SomeFeed\""
    ]
}
```
As you can see, with `install_args` the command that is executed becomes `--installargs --pre`. 



Discussion:
Files identified in the description:
* [lib/ansible/modules/windows/win_chocolatey.ps1](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/windows/win_chocolatey.ps1)

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 @dagwieers @elventear @jborean93 @jhawkesworth @nitzmahone @petemounce @ptemplier @smadam813 @trondhindenes
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@andmos Shouldn't be hard to implement. Would you be willing to implement this ?
Sure, I can have a look. Should be as easy as just adding another parameter. 

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
@@ -111,6 +111,13 @@
       - See notes in C(proxy_username) when dealing with double quotes in a
         password.
     version_added: '2.4'
+  allow_prerelease:
+    description:
+      - Allow install of prerelease packages.
+      - If state C(state) is C(latest) the highest prerelease package will be installed.
+    type: bool
+    default: 'no'
+    version_added: '2.6'
 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


Test patch: