I’m having trouble setting Ansible with WinRM. Here’s my environment:
10.10.50.4 - Win1 - the windows computer im trying to connect to from Ansible (i’ve added this to the hosts file on my ansible host)
10.10.50.6 - Win2 - another windows host
10.10.50.5 - Ansible host (running Ubuntu 12.04)
On Win1 I have setup a remoting endpoint using SSL (btw, the doc doesn’t state wether SSL is required or recommended. non-ssl http connections should be an option imho)
From 10.10.50.6 I can initiate a SSL-based PSremoting session to 10.10.50.4, which should prove that the remoting endpoint and ssl is correctly setup:
$cred = Get-credential
$options = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
New-PSSession -ComputerName “10.10.50.4” -UseSSL -Credential $cred -SessionOption $options
This opens a session without warnings.
Here’s my hosts file in ansible:
azureuser@th-ansible10:~/AnsibleTest/pstest$ cat hosts
[windows]
Win1
and here’s my windows groupvar file:
azureuser@th-ansible10:~/AnsibleTest/pstest/group_vars$ cat windows.yml
it is suggested that these be encrypted with ansible-vault:
ansible-vault edit group_vars/windows.yml
ansible_ssh_user: thadministrator
ansible_ssh_pass:
ansible_ssh_port: 5986
ansible_connection: winrm
Here’s the command I’m attempting:
azureuser@th-ansible10:~/AnsibleTest/pstest$ ansible windows -i hosts -m win_ping -vvvv
ESTABLISH WINRM CONNECTION FOR USER: thadministrator on PORT 5986 TO win1
WINRM CONNECT: transport=plaintext endpoint=https://win1:5986/wsman
WINRM CONNECTION ERROR: Bad HTTP response returned from server. Code 401
WINRM CONNECT: transport=plaintext endpoint=http://win1:5986/wsman
win1 | FAILED => Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/ansible-1.7-py2.7.egg/ansible/runner/init.py”, line 526, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File “/usr/local/lib/python2.7/dist-packages/ansible-1.7-py2.7.egg/ansible/runner/init.py”, line 628, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File “/usr/local/lib/python2.7/dist-packages/ansible-1.7-py2.7.egg/ansible/runner/init.py”, line 799, in _executor_internal_inner
conn = self.connector.connect(actual_host, actual_port, actual_user, actual_pass, actual_transport, actual_private_key_file)
File “/usr/local/lib/python2.7/dist-packages/ansible-1.7-py2.7.egg/ansible/runner/connection.py”, line 34, in connect
self.active = conn.connect()
File “/usr/local/lib/python2.7/dist-packages/ansible-1.7-py2.7.egg/ansible/runner/connection_plugins/winrm.py”, line 130, in connect
self.protocol = self._winrm_connect()
File “/usr/local/lib/python2.7/dist-packages/ansible-1.7-py2.7.egg/ansible/runner/connection_plugins/winrm.py”, line 86, in _winrm_connect
protocol.send_message(‘’)
File “/usr/local/lib/python2.7/dist-packages/winrm/protocol.py”, line 160, in send_message
return self.transport.send_message(message)
File “/usr/local/lib/python2.7/dist-packages/winrm/transport.py”, line 63, in send_message
response = urlopen(request, timeout=self.timeout)
File “/usr/lib/python2.7/urllib2.py”, line 126, in urlopen
return _opener.open(url, data, timeout)
File “/usr/lib/python2.7/urllib2.py”, line 400, in open
response = self._open(req, data)
File “/usr/lib/python2.7/urllib2.py”, line 418, in _open
‘_open’, req)
File “/usr/lib/python2.7/urllib2.py”, line 378, in _call_chain
result = func(*args)
File “/usr/lib/python2.7/urllib2.py”, line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File “/usr/lib/python2.7/urllib2.py”, line 1180, in do_open
r = h.getresponse(buffering=True)
File “/usr/lib/python2.7/httplib.py”, line 1030, in getresponse
response.begin()
File “/usr/lib/python2.7/httplib.py”, line 407, in begin
version, status, reason = self._read_status()
File “/usr/lib/python2.7/httplib.py”, line 365, in _read_status
line = self.fp.readline()
File “/usr/lib/python2.7/socket.py”, line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 104] Connection reset by peer
I don’t know why this is happening, and I realize that this is very much beta code. However, there are some (potentially important) points left out from the doc:
- Is SSL required, or should this work using http-based connections?
- What requirements are there on the ssl cert being used? Does the ansible node need the public key of the cert being used on the windows side?