# Connection refused

**URL:** <https://forum.ansible.com/t/connection-refused/17892>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [April 2, 2015, 5:31pm UTC](https://forum.ansible.com/t/connection-refused/17892 "2015-04-02T17:31:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [April 2, 2015, 5:31pm UTC](https://forum.ansible.com/t/connection-refused/17892/1 "2015-04-02T17:31:25Z")

</div>

I’m having trouble getting win\_ping to work with or without SSL. Here are my details…

CentOS Linux release 7.1.1503 (Core)

ansible 1.8 (devel 57d2622c8c) last updated 2014/10/17 18:19:13 (GMT -500)

using pywinrm-0.0.3-py2.7

I started winrm on the remote node using[this script from Hindenes/Church](https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1)

ansible\_ssh\_user: ansible

ansivle\_ssh\_pass: ansible123

ansible\_ssh\_port: 5986

ansible\_connection: winrm

[windows]

ComputerName

[ansmgr@dhcp1-60-20 ansible]$ ansible windows -m win\_ping -vvvv

\<[www.example.com](http://ads-6999.am.ad.seagate.com)\> ESTABLISH CONNECTION FOR USER: ansmgr

\<[www.example.com](http://ads-6999.am.ad.seagate.com)\> REMOTE\_MODULE win\_ping

\<[www.example.com](http://ads-6999.am.ad.seagate.com)\> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=/home/ansmgr/.ansible/cp/ansible-ssh-%h-%p-%r -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 [www.example.com](http://ads-6999.am.ad.seagate.com) /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1427994666.99-36837830948182 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1427994666.99-36837830948182 && echo $HOME/.ansible/tmp/ansible-tmp-1427994666.99-36837830948182’

[www.example.com](http://ads-6999.am.ad.seagate.com) | FAILED =\> SSH encountered an unknown error. The output was:

OpenSSH\_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013

debug1: Reading configuration data /etc/ssh/ssh\_config

debug1: /etc/ssh/ssh\_config line 56: Applying options for \*

debug1: auto-mux: Trying existing master

debug1: Control socket “/home/ansmgr/.ansible/cp/ansible-ssh-www.example.com-22-ansmgr” does not exist

debug2: ssh\_connect: needpriv 0

debug1: Connecting to [www.example.com](http://ads-6999.am.ad.seagate.com) [123.123.123.123] port 22.

debug2: fd 3 setting O\_NONBLOCK

debug1: connect to address 123.123.123.123 port 22: Connection refused

ssh: connect to host [www.example.com](http://ads-6999.am.ad.seagate.com) port 22: Connection refused

---

<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:** [April 2, 2015, 7:44pm UTC](https://forum.ansible.com/t/connection-refused/17892/2 "2015-04-02T19:44:45Z")

</div>

> [windows]

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [April 2, 2015, 8:22pm UTC](https://forum.ansible.com/t/connection-refused/17892/3 "2015-04-02T20:22:58Z")

</div>

Thanks for the tip. In my case it would be simpler to keep everything in the hosts file.

But actually I did have the ansible\_ssh vars in the etc/ansible/group\_vars/windows.yml

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [April 7, 2015, 1:29pm UTC](https://forum.ansible.com/t/connection-refused/17892/4 "2015-04-07T13:29:37Z")

</div>

It looks like you are making an ssh connection so it appears your vars are not getting picked up.  
Since your config has a user ‘ansible’ but the logging output shows you are connecting as ‘ansmgr’, and clearly connecting to port 22 not 5986 I am wondering if you are picking up the inventory / hosts file that you expect?

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [April 9, 2015, 5:12pm UTC](https://forum.ansible.com/t/connection-refused/17892/5 "2015-04-09T17:12:44Z")

</div>

Actually I’m trying to connect to a Windows machine so I can’t use ssh. In that case are the contents of my windows.yml file correct for connecting to a windows machine. I’ve tried using port 5986 and 5985 (using a cert and ssl) but neither works.

windows.yml file contains…

ansible\_ssh\_user: ansmgr

ansivle\_ssh\_pass: ansible123

ansible\_ssh\_port: 5986

ansible\_connection: winrm

Also someone told me that the user and password in the windows.yml file must match the username and password of the active account (logged in) on the windows machine. Is this correct?

I was also told that the active account must be a local account not a domain account. Is this correct?

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [April 10, 2015, 12:58pm UTC](https://forum.ansible.com/t/connection-refused/17892/6 "2015-04-10T12:58:19Z")

</div>

Your vars look correct but the logging output from ansible-playbook when you run it appeared to show it was attempting to use SSH to connect, which as you say isn’t going to work against a windows machine.

Is [www.example.com](http://www.example.com) actually one of the machines listed as belonging to your [windows] group? If not the default connection, ssh, will be attempted.

The user does not need to be logged in on the windows machine, but the user has to exist (and ansible needs to know the correct password of course).

Since you are running ansible 1.8 then you will need to connect as a local user on the windows machine. If you are able to use 1.9 then you can connect using a domain user if you have pykerberos installed. You will need to specify the username like  
user@FULL.DOMAIN.NAME in order to use a domain user.

Hope that helps,

Jon

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [April 10, 2015, 1:16pm UTC](https://forum.ansible.com/t/connection-refused/17892/7 "2015-04-10T13:16:51Z")

</div>

Looks like you might be hitting the same thing as described here:

[https://groups.google.com/forum/#!topic/ansible-project/otFPejRWX-Y](https://groups.google.com/forum/#!topic/ansible-project/otFPejRWX-Y)

maybe your group\_vars/windows.yml doesn’t start with

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [April 26, 2015, 1:28am UTC](https://forum.ansible.com/t/connection-refused/17892/8 "2015-04-26T01:28:22Z")

</div>

It’s fixed now. Here’s my windows.yml file contents

ansible\_ssh\_user: ansible  
ansivle\_ssh\_pass: ansible123  
ansible\_ssh\_port: 5986  
ansible\_connection: winrm

It seems that the 3rd line of my windows.yml file “ansible\_ssh\_port: 5986” was not doing it’s job because I appended my computer name with the port number and everything worked fine. So I’ve deleted the 3rd line of my windows.yml file and now my host file is

[windows]  
ComputerName:5986
