Connection reset by peer

I’ve been trying to get win_ping to work for weeks now so I’d be so grateful if someone could help identify my problem.

System details

Fedora 20
Ansible ver 1.8

Here are my setup commands (from a clean Fedora install).

sudo yum install gcc
sudo yum install git
sudo yum install python
sudo yum install python-setuptools python-setuptools-devel
sudo yum install python-devel
sudo yum install python2-devel
sudo yum install python-pip
sudo yum install rpm-build
sudo git clone git://github.com/ansible/ansible.git /etc/ansible

The following command never works for me.
cd /etc/ansible
sudo make rpm

sed “s/%VERSION%/1.8/” docs/man/man1/ansible-doc.1.asciidoc.in > docs/man/man1/ansible-doc.1.asciidoc
/bin/sh: docs/man/man1/ansible-doc.1.asciidoc: Permission denied
make: *** [docs/man/man1/ansible-doc.1.asciidoc] Error 1

sudo pip install http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm
sudo cp /etc/ansible/lib/ansible/module_utils/powershell.ps1 /usr/lib/python2.7/site-packages/ansible/module_utils

source ./hacking/env-setup

How do I install Python 2.7 without installing Python 3.x?
Are any of my setup commands above redundant or unnecessary?

Here is my inventory

[ansmgr@dhcp1-59-159 ansible]$ cat hosts
[windows]

123.123.123.123

Here I specify that I’m using powershell instead of ssh

[ansmgr@dhcp1-59-159 group_vars]$ cat windows.yml
ansible_ssh_user: ansmgr

ansible_ssh_pass: ansiblepw
ansible_ssh_port: 5986
ansible_connection: winrm

I have installed powershell on my remote node and have run the Trond Hindenes script with “Basic -value $true”

Here is the debug output of my win_ping command.

[ansmgr@dhcp1-59-159 ansible]$ ansible all -i hosts -m win_ping --ask-vault-pass -vvvv
Vault password:
<123.123.123.123> ESTABLISH WINRM CONNECTION FOR USER: ansmgr on PORT 5986 TO 123.123.123.123
<123.123.123.123> WINRM CONNECT: transport=plaintext endpoint=https://123.123.123.123:5986/wsman
<123.123.123.123> WINRM CONNECTION ERROR: 500 WinRMTransport. [Errno 104] Connection reset by peer
<123.123.123.123> WINRM CONNECT: transport=plaintext endpoint=http://123.123.123.123:5986/wsman
123.123.123.123 | FAILED => Traceback (most recent call last):
File “/etc/ansible/lib/ansible/runner/init.py”, line 559, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File “/etc/ansible/lib/ansible/runner/init.py”, line 732, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File “/etc/ansible/lib/ansible/runner/init.py”, line 895, in _executor_internal_inner
conn = self.connector.connect(actual_host, actual_port, actual_user, actual_pass, actual_transport, actual_private_key_file)
File “/etc/ansible/lib/ansible/runner/connection.py”, line 44, in connect
self.active = conn.connect()
File “/etc/ansible/lib/ansible/runner/connection_plugins/winrm.py”, line 132, in connect
self.protocol = self._winrm_connect()
File “/etc/ansible/lib/ansible/runner/connection_plugins/winrm.py”, line 86, in _winrm_connect
protocol.send_message(‘’)
File “/usr/lib/python2.7/site-packages/winrm/protocol.py”, line 173, in send_message
return self.transport.send_message(message)
File “/usr/lib/python2.7/site-packages/winrm/transport.py”, line 76, in send_message
response = urlopen(request, timeout=self.timeout)
File “/usr/lib64/python2.7/urllib2.py”, line 127, in urlopen
return _opener.open(url, data, timeout)
File “/usr/lib64/python2.7/urllib2.py”, line 404, in open
response = self._open(req, data)
File “/usr/lib64/python2.7/urllib2.py”, line 422, in _open
‘_open’, req)
File “/usr/lib64/python2.7/urllib2.py”, line 382, in _call_chain
result = func(*args)
File “/usr/lib64/python2.7/urllib2.py”, line 1216, in http_open
return self.do_open(httplib.HTTPConnection, req)
File “/usr/lib64/python2.7/urllib2.py”, line 1189, in do_open
r = h.getresponse(buffering=True)
File “/usr/lib64/python2.7/httplib.py”, line 1045, in getresponse
response.begin()
File “/usr/lib64/python2.7/httplib.py”, line 409, in begin
version, status, reason = self._read_status()
File “/usr/lib64/python2.7/httplib.py”, line 365, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File “/usr/lib64/python2.7/socket.py”, line 476, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 104] Connection reset by peer

There must be a problem with my encryption because when I run this line in powershell it works.

winrm set winrm/config/service ‘@{AllowUnencrypted=“true”}’

Okay this is fixed. The values assigned to the variables “ansible_ssh_user” and “ansible_ssh_pass” must:

  1. Exactly match an account on the windows machine with admin privileges (account must exist but need NOT be current active login)

  2. If you are using SSL and the value of winrm/config/service/AllowUnencrypted is true (this is the default) the values in ansible\group_vars\windows.yml must exactly match the username and password that was submitted to generate the SSL web certificate.

In my case I also had to append the computer name with the port number in the inventory like this

[windows]
ComputerName:5986

(or 5985 for AllowUnedcrypted=“true” type this command in powershell PS C:\winrm set winrm/config/service ‘@{AllowUnencrypted=“true”}’

done.