connection with windows

Hello, i am running ansible 1.9.1 on a Ubuntu server 14.04.2, my remote machine is a windows 7 sp1.
i have the following files and error message, i don’t understand where the issue is…

/etc/ansible/group_vars/windows.yml

ansible_ssh_user: AnsibleUser
ansible_ssh_pass: ansiblepass
ansible_ssh_port: 5986
ansible_connection: winrm

/etc/ansible/winplaybook.yml

  • hosts: WIN-F6531IBP8HG tasks:
    • name: unarchive unarchive: src=/tmp/hello.txt.zip dest=C:\Users\Querso\Desktop

/etc/ansible/hosts

WIN-F6531IBP8HG

i have python 2.7.6 and i have the following error message:
ansible-playbook /etc/ansible/winplaybook.yml -i WIN-F6531IBP8HG,

PLAY [WIN-F6531IBP8HG] ********************************************************

GATHERING FACTS ***************************************************************
fatal: [WIN-F6531IBP8HG] => SSH Error: Permission denied (publickey,password,keyboard-interactive).
while connecting to 192.168.79.133:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

TASK: [unarchive] *************************************************************
FATAL: no hosts matched or all hosts have already failed – aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/guillaume/winplaybook.retry

WIN-F6531IBP8HG : ok=0 changed=0 unreachable=1 failed=0

if i try to ping windows:
ansible WIN-F6531IBP8HG -m win_ping
WIN-F6531IBP8HG | FAILED => SSH Error: Permission denied (publickey,password,keyboard-interactive).
while connecting to 192.168.79.133:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

thanks for your help!!

EDIT: my files are now

/etc/ansible/group_vars/windows/windows.yml
ansible_ssh_user: AnsibleUser
ansible_ssh_pass: ansiblepass
ansible_ssh_port: 5986
ansible_connection: winrm

/etc/ansible/hosts
[windows]
WIN-F6531IBP8NG

the ping is working but sometimes it fails with this message:
WIN-F6531IBP8HG | FAILED >> {
“failed”: true,
“msg”: “\nProcess is terminated due to StackOverflowException.\n”,
“parsed”: false
}
or this one:
WIN-F6531IBP8HG | FAILED >> {
“failed”: true,
“msg”: “”,
“parsed”: false
}

but when i run the playbook, it still tries to connect via ssh and not winrm so it doesn’t seem to see my windows.yml file but i don’t know how to deal with this issue…

Looks like you just need to add your server into a group called windows - the example here shows the group
http://docs.ansible.com/intro_windows.html#inventory

So your inventory file needs to look like this:

[windows]
WIN-F6531IBP8HG

The group vars will then take effect for your host and ansible will know to connect via winrm instead of ssh, which it is trying at the moment (which isn’t going to work as Windows doesn’t understand SSH).

Hope this helps,

Jon

i have done this as said in my edit but it is not working for the playbook. do i have anything else to do to make it run properly?

Looks like you have hit the windows management framework 3.0 bug described in the blue box here:

http://docs.ansible.com/intro_windows.html#windows-system-prep

Since win_ping is working for you now, you just need to install the hotfix to get up and running:

http://support.microsoft.com/kb/2842230

Jon

i can’t install the hotfix, i am stuck on the terms ans conditions page…
is this bug related to ansible-playbook because i can make a ping but not run my playbook?

It is a bug in windows management framework which incorrectly sets the amount of memory available to processes connected via winrm - its really outside Ansible’s domain.

If you can’t install the hotfix another way to get round it is to install windows managment framework 4, which doesn’t have this particular bug (and has the advantage of giving you powershell 4.0 which has a number of useful extra features over powershell 3.0).

Hope this helps

Jon

On a side note: To me it looks like you’re trying to use the “unarchive” module on a windows node. That won’t work. You need to use a module listed in “Windows modules”: http://docs.ansible.com/list_of_windows_modules.html

thank you for your answer, indeed it is not a windows package but sadly it didn’t solved my problem…

Maybe try different web browser to download the hotfix?
You either need the hotfix or Windows Management Framework 4.0 as far as I can tell.
Jon

i have powershell 4 now, but it is still not working porperly. it seems that ansible cannot find my windows.yml file. even if is set those variables in my hosts file, it doesn’t work.

not sure if this can help you but i am running windows locally as a vm.

Running windows as a vm should not in itself be a problem.

What error are you getting now?

i have the following files:

/etc/ansible/hosts

[windows]

WIN-F5631IBP8HG ansible_connection=winrm ansible_ssh_user=AnsibleUser ansible_ssh_pass=ansiblepass ansible_ssh_port=5986

etc/ansible/winplaybook.yml

  • name: Run powershell script

hosts: windows

gather_facts: false

connection: winrm

tasks:

  • name: Run powershell script

script: C:/Users/AnsibleUser/Desktop/helloworld.ps1

the ping is working perfectly (thanks to powershell 4) and i have the following message:

ansible-playbook /etc/ansible/winplaybook.yml -i windows, -vvvv

PLAY [Run powershell script] **************************************************

TASK: [Run powershell script] *************************************************

ESTABLISH WINRM CONNECTION FOR USER: guillaume on PORT 5986 TO windows

WINRM CONNECT: transport=plaintext endpoint=https://windows:5986/wsman

WINRM CONNECTION ERROR: 500 WinRMTransport. [Errno 111] Connection refused

fatal: [windows] => 500 WinRMTransport. [Errno 111] Connection refused

FATAL: all hosts have already failed – aborting

PLAY RECAP ********************************************************************

to retry, use: --limit @/home/guillaume/winplaybook.retry

windows : ok=0 changed=0 unreachable=1 failed=0

Not sure why this is failing for you but here’s some things you can try

1/ Check you have run the setup script on your windows host:

https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1
(linked from here: http://docs.ansible.com/intro_windows.html#windows-system-prep)

2/ Try checking the event log on your windows machine to see if you can see why connection is being refused.

3/ check the firewall configuration to ensure that it is possible to connect to port 5986 on your windows machine from your ansible controller.

Hope this helps

Jon