win_chocolatey not a legal parameter

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/”,
“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?

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

Install common packages

  • name: Install common packages from chocolatey
    win_chocolatey:
    package: notepadplusplus
    state: present
    showlog: true

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.

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/”,
“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写道:

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.

Nope, doesn’t work.

My file structure is:

windows_playbook.yml
group_vars/windows
inventory/win

My playbook:

`

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/”, “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/”, “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.

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.

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.

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.

solution:

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

for windows modules the detected extension is .ps1

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

https://github.com/ansible/ansible-modules-extras/issues/159

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.

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.

I’m experiencing this as well.

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?

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

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.