# Intermittent connection refused errors using rax module

**URL:** <https://forum.ansible.com/t/intermittent-connection-refused-errors-using-rax-module/14814>\
**Category:** Ansible Project\
**Created:** [March 20, 2014, 4:42pm UTC](https://forum.ansible.com/t/intermittent-connection-refused-errors-using-rax-module/14814 "2014-03-20T16:42:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmy\_Prescott1](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@Jimmy\_Prescott1](https://forum.ansible.com/u/Jimmy_Prescott1)\
**Post date:** [March 20, 2014, 4:42pm UTC](https://forum.ansible.com/t/intermittent-connection-refused-errors-using-rax-module/14814/1 "2014-03-20T16:42:51Z")

</div>

Hello,

Searched around before posting this but I was unable to find anything useful.

Anyway I am using the rax module to provision a server in the Rackspace Cloud using pyrax etc. The problem is that SOMETIMES the play will fail with a connection refused error.:

PLAY [Wait for port 22 to be ready] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [wait\_for port=22 delay=20] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [testing6] =\> {‘msg’: ‘FAILED: [Errno 111] Connection refused’, ‘failed’: True}

FATAL: all hosts have already failed – aborting

I tried adding the wait\_for with a delay of 20 but maybe I am doing it wrong. Here is what my play looks like up to the point of failure:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 21, 2014, 12:09pm UTC](https://forum.ansible.com/t/intermittent-connection-refused-errors-using-rax-module/14814/2 "2014-03-21T12:09:43Z")

</div>

I believe this email ended up being delayed a bit. Jimmy and I worked through this yesterday and changed the wait\_for task to look like:

- local\_action: wait\_for port=22 delay=20 hostname=“{{ ansible\_ssh\_host }}”

---

<div class="post-metadata">

**Author:** ![Jimmy\_Prescott1](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@Jimmy\_Prescott1](https://forum.ansible.com/u/Jimmy_Prescott1)\
**Post date:** [March 21, 2014, 1:52pm UTC](https://forum.ansible.com/t/intermittent-connection-refused-errors-using-rax-module/14814/3 "2014-03-21T13:52:21Z")

</div>

It hasn’t failed since I made the change so thank you! Slight correction though in case anyone else runs into this problem. hostname=“{{ ansible\_ssh\_host }}” is actually host=“{{ ansible\_ssh\_host }}”

---

<div class="post-metadata">

**Author:** ![Brian\_Spacecraft](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@Brian\_Spacecraft](https://forum.ansible.com/u/Brian_Spacecraft)\
**Post date:** [May 20, 2015, 7:47pm UTC](https://forum.ansible.com/t/intermittent-connection-refused-errors-using-rax-module/14814/4 "2015-05-20T19:47:03Z")

</div>

I see a similar issue probably 1/10 times I run a playbook I’m developing.

I am using wait\_for after changing sshd listening port

> - hosts: staging  
> tasks:
> - name: Wait for ssh access on new port  
> wait\_for: delay=20 connect\_timeout=30 host=“{{ ansible\_ssh\_host }}” port=“{{ ansible\_ssh\_port }}”

And here is the error I get (I’ve substituted the actual port with , and my username with ):

> GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> \<162.209.100.204\> ESTABLISH CONNECTION FOR USER:   
> \<162.209.100.204\> REMOTE\_MODULE setup  
> \<162.209.100.204\> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/Users/brian/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o Port= -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User= -o ConnectTimeout=300 162.209.100.204 /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1432149978.13-279657059089785 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1432149978.13-279657059089785 && echo $HOME/.ansible/tmp/ansible-tmp-1432149978.13-279657059089785’  
> fatal: [162.209.100.204] =\> SSH Error: ssh: connect to host 162.209.100.204 port : Connection refused  
> while connecting to 162.209.100.204:

This probably doesn’t have anything to do with the rax module. My playbook does the following:

1. Provision rackspace servers with the rax module
2. Apply a common role that as its last step reconfigures sshd to listen on a nonstandard port and only allow login by 
3. Adds hosts to a new in-memory group (staging) with updated ansible\_ssh\_user and ansible\_ssh\_port
4. Runs the wait\_for play above against these hosts

The error happens when it gathers facts for the wait\_for play.

Any help would be much appreciated!
