# win\_chocolatey not a legal parameter

**URL:** <https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 8, 2014, 5:47am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983 "2014-12-08T05:47:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [December 8, 2014, 5:47am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/1 "2014-12-08T05:47:30Z")

</div>

I’m having trouble with win\_chocolatey module in a playbook.

I upgraded from 1.7 to 1.9 and then ran the following successfully:

> ansible windows -i inventories/windows -m win\_chocolatey -c winrm -u administrator -k -a ‘package=notepadplusplus’  
> SSH password:  
> 1.2.3.4 | success \>\> {  
> “changed”: true,  
> “chocolatey command”: “C:\ProgramData\chocolatey\bin\choco.exe install notepadplusplus -source [https://chocolatey.org/api/v2/](https://chocolatey.org/api/v2/)”,  
> “chocolatey\_success”: “true”

> }

So then I added to a playbook as per the documentation but I get the following error:

> ansible-playbook hosts\_windows.yml -i inventories/windows  
> ERROR: win\_chocolatey is not a legal parameter in an Ansible task or handler

Why would ansible see the module, but ansible-playbook fail?

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [December 9, 2014, 12:25am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/2 "2014-12-09T00:25:44Z")

</div>

Could you paste the task from your playbook that’s causing the error?

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [December 9, 2014, 2:40am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/3 "2014-12-09T02:40:29Z")

</div>

# Install common packages

- name: Install common packages from chocolatey  
win\_chocolatey:  
package: notepadplusplus  
state: present  
showlog: true

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [December 9, 2014, 5:13am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/4 "2014-12-09T05:13:54Z")

</div>

Trying using ansible-playbook with -c winrm, or add  
ansible\_connection=winrm to your inventory for Windows hosts.

Ansible will only find PowerShell modules when using the winrm connection.

---

<div class="post-metadata">

**Author:** ![Ashley\_Yanan\_Yuan](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@Ashley\_Yanan\_Yuan](https://forum.ansible.com/u/Ashley_Yanan_Yuan)\
**Post date:** [December 12, 2014, 7:35am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/5 "2014-12-12T07:35:29Z")

</div>

Hello guys,

I’m new to ansible. And I’m using ansible 1.9 to install apps to my windows machine. But i’ve always run into this problem when using the following command:

ansible windows -m win\_chocolatey -c winrm -u Administrator -a ‘package=notepadplusplus’ --ask-vault-pass -vvvv

error messages:

> WINRM RESULT \<Response code 0, out “{ “changed”: f”, err “Starting t”\>  
> ide-qa-3-pc | FAILED \>\> {  
> “changed”: false,  
> “chocolatey command”: “choco.exe install notepadplusplus -source [https://chocolatey.org/api/v2/](https://chocolatey.org/api/v2/)”,  
> “failed”: true,  
> “msg”: "Install error: "  
> }

I’ve run into the same error when I run ansible-playbook. By the way, I could using win\_ping to connect my windows host and run win\_msi to install apps successfully.

Why win\_chocolatey failed? I’m really appreciate to any of your suggestions.

在 2014年12月8日星期一UTC+8下午1时47分30秒，Rob White写道：

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [December 15, 2014, 4:38am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/6 "2014-12-15T04:38:16Z")

</div>

If you run the same command with -vvvvv (5 v's), you'll get everything sent  
back on stderr instead of just "Starting t". There may be something in  
that output to provide more details on what went wrong.

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [December 16, 2014, 6:03am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/7 "2014-12-16T06:03:17Z")

</div>

Nope, doesn’t work.

My file structure is:

windows\_playbook.yml  
group\_vars/windows  
inventory/win

My playbook:

`

---

<div class="post-metadata">

**Author:** ![Ashley\_Yuan](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Ashley\_Yuan](https://forum.ansible.com/u/Ashley_Yuan)\
**Post date:** [December 16, 2014, 6:26am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/8 "2014-12-16T06:26:53Z")

</div>

Thank you Chris for that. I’ve got the whole error messages, but I don’t know how to resolve it:

> WINRM RESULT \<Response code 0, out “{ “changed”: f”, err “Starting t”\>  
> WINRM STDOUT { “changed”: false, “chocolatey command”: “choco.exe install git -source [https://chocolatey.org/api/v2/](https://chocolatey.org/api/v2/)”, “msg”: "Install error: ", “failed”: true }  
> WINRM STDERR **Starting the CLR failed with HRESULT 80004005.**  
> failed: [ide-qa-2-pc] =\> {“changed”: false, “chocolatey command”: “choco.exe install git -source [https://chocolatey.org/api/v2/](https://chocolatey.org/api/v2/)”, “failed”: true}  
> msg: Install error:  
> FATAL: all hosts have already failed – aborting  
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> to retry, use: --limit @/home/liferay/install-windows.retry

I’m using “source hacking/env-setup” to install my ansible, any suggestions on this problem?

Looking forward for your help.

---

<div class="post-metadata">

**Author:** ![Ashley\_Yuan](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Ashley\_Yuan](https://forum.ansible.com/u/Ashley_Yuan)\
**Post date:** [December 16, 2014, 6:40am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/9 "2014-12-16T06:40:29Z")

</div>

Hi Rob,

Maybe you could try this structure in your playbook file:

> * * *
> 
> - hosts: windows  
> tasks:
> - name: install  
> win\_chocolatey:  
> package: notepadplusplus  
> state: present
> 
> # Install git
> 
> - win\_chocolatey:  
> package: git

Hope that helps.

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [December 16, 2014, 6:47am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/10 "2014-12-16T06:47:09Z")

</div>

Thanks for the suggestion Ashley.

I have previously tried that structure but i still get the same error complaining about win\_chocolatey not being a legal parameter.

---

<div class="post-metadata">

**Author:** ![Ashley\_Yuan](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Ashley\_Yuan](https://forum.ansible.com/u/Ashley_Yuan)\
**Post date:** [December 16, 2014, 7:05am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/11 "2014-12-16T07:05:18Z")

</div>

Be careful with using ‘space’ in playbook file.

I’m no longer run into that error after change to my example structure. Only run into the **HRESULT 80004005** error now. Sorry for haven’t helped.

---

<div class="post-metadata">

**Author:** ![Netanel\_Maman](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@Netanel\_Maman](https://forum.ansible.com/u/Netanel_Maman)\
**Post date:** [December 17, 2014, 11:11am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/12 "2014-12-17T11:11:16Z")

</div>

solution:

create this file: ansible/lib/ansible/modules/extras/windows/ **init**.py  
make clean  
make install

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 17, 2014, 3:01pm UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/13 "2014-12-17T15:01:18Z")

</div>

for windows modules the detected extension is .ps1

---

<div class="post-metadata">

**Author:** ![Netanel\_Maman](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@Netanel\_Maman](https://forum.ansible.com/u/Netanel_Maman)\
**Post date:** [December 17, 2014, 3:07pm UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/14 "2014-12-17T15:07:34Z")

</div>

I opened issue with explain why it’s true only in theory.

[https://github.com/ansible/ansible-modules-extras/issues/159](https://github.com/ansible/ansible-modules-extras/issues/159)

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [December 18, 2014, 2:42am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/15 "2014-12-18T02:42:13Z")

</div>

Thanks!

I saw the file was already added to the devel branch. I downloaded that branch and chocolatey module can now be called from playbook.

---

<div class="post-metadata">

**Author:** ![Jason\_C](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jason\_C](https://forum.ansible.com/u/Jason_C)\
**Post date:** [January 22, 2015, 10:29am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/16 "2015-01-22T10:29:53Z")

</div>

Hi Rob,

What was your final solution? I am using the “devel” branch of the ansible-modules-extras and are still experiencing the same issue as you originally posted.

---

<div class="post-metadata">

**Author:** ![Dennis\_Micky\_Jensen](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@Dennis\_Micky\_Jensen](https://forum.ansible.com/u/Dennis_Micky_Jensen)\
**Post date:** [January 22, 2015, 8:35pm UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/17 "2015-01-22T20:35:43Z")

</div>

I’m experiencing this as well.

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [January 22, 2015, 11:16pm UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/18 "2015-01-22T23:16:29Z")

</div>

If you look in your module directory (my machine it is /usr/lib/python2.7/site-packages/ansible/modules/extras/windows/) do you see a **init**.py file?

---

<div class="post-metadata">

**Author:** ![Jason\_C](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jason\_C](https://forum.ansible.com/u/Jason_C)\
**Post date:** [January 23, 2015, 2:41am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/19 "2015-01-23T02:41:57Z")

</div>

Hi Rob,

I have cloned ansible-modules-extras to a separate directory. Under that directory …/modules/ansible-modules-extras/windows/ there is a file named **init**.py.

Similar to the issues you were experiencing i can run an ansible command using the win\_chocolatey module but when running a playbook I consistently get the error "

win\_chocolatey is not a legal parameter in an Ansible task or handler"

I am unsure of where to go from here. Any advice is appreciated.

Jason

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [January 23, 2015, 6:02am UTC](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983/20 "2015-01-23T06:02:30Z")

</div>

How are you defining your hosts?

You need to make sure the method is WinRM. As Chris mentioned earlier in this thread, ansible will only recognize PowerShell modules when using winrm type.

[Next page](https://forum.ansible.com/t/win-chocolatey-not-a-legal-parameter/16983.md?page=2)
