# ssh works for first few tasks then fails (on different tasks each attempt)

**URL:** <https://forum.ansible.com/t/ssh-works-for-first-few-tasks-then-fails-on-different-tasks-each-attempt/16860>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [November 23, 2014, 11:53pm UTC](https://forum.ansible.com/t/ssh-works-for-first-few-tasks-then-fails-on-different-tasks-each-attempt/16860 "2014-11-23T23:53:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Whiteside1](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@David\_Whiteside1](https://forum.ansible.com/u/David_Whiteside1)\
**Post date:** [November 23, 2014, 11:53pm UTC](https://forum.ansible.com/t/ssh-works-for-first-few-tasks-then-fails-on-different-tasks-each-attempt/16860/1 "2014-11-23T23:53:36Z")

</div>

It worked at ansible v1.5, now I have the occasional issue below with the latest version 1.7.2. Manually sshing never has any issues.

$ ansible-playbook -s -i ./inventoryfile plays.yml -vvvv

PLAY [webserver] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [webserver]

TASK: [webserver | Install nginx] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [webserver] =\> {“changed”: false}

TASK: [webserver | start nginx] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [webserver] =\> {“changed”: false, “enabled”: true, “name”: “nginx”, “state”: “started”}

TASK: [webserver | configure default webpage for nginx] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 ESTABLISH CONNECTION FOR USER: ubuntu  
 EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘UserKnownHostsFile=/dev/null’, ‘-o’, ‘CheckHostIP=no’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-i’, ‘/home/ubuntu/.ssh/mykey’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, u’HOSTNAME’, u’/bin/sh -c 'sudo -k && sudo -H -S -p “[sudo via ansible, key=byvvbhgjlxzbdlcslyfnckefapqkxjpm] password: " -u root /bin/sh -c '”'“'echo SUDO-SUCCESS-byvvbhgjlxzbdlcslyfnckefapqkxjpm; rc=0; [-r “/usr/share/nginx/www/index.html”] || rc=2; [-f “/usr/share/nginx/www/index.html”] || rc=1; [-d “/usr/share/nginx/www/index.html”] && echo 3 && exit 0; (/usr/bin/md5sum /usr/share/nginx/www/index.html 2\>/dev/null) || (/sbin/md5sum -q /usr/share/nginx/www/index.html 2\>/dev/null) || (/usr/bin/digest -a md5 /usr/share/nginx/www/index.html 2\>/dev/null) || (/sbin/md5 -q /usr/share/nginx/www/index.html 2\>/dev/null) || (/usr/bin/md5 -n /usr/share/nginx/www/index.html 2\>/dev/null) || (/bin/md5 -q /usr/share/nginx/www/index.html 2\>/dev/null) || (/usr/bin/csum -h MD5 /usr/share/nginx/www/index.html 2\>/dev/null) || (/bin/csum -h MD5 /usr/share/nginx/www/index.html 2\>/dev/null) || (echo “${rc} /usr/share/nginx/www/index.html”)'”'"''‘]  
 EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘UserKnownHostsFile=/dev/null’, ‘-o’, ‘CheckHostIP=no’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-i’, ‘/home/ubuntu/.ssh/mykey’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, u’HOSTNAME’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1416786433.51-62781121556067 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1416786433.51-62781121556067 && echo $HOME/.ansible/tmp/ansible-tmp-1416786433.51-62781121556067’”]  
fatal: [webserver] =\> SSH encountered an unknown error. The output was:  
OpenSSH\_6.6.1, OpenSSL 1.0.1f 6 Jan 2014  
debug1: Reading configuration data /home/ubuntu/.ssh/config  
debug1: Reading configuration data /etc/ssh/ssh\_config  
debug1: /etc/ssh/ssh\_config line 19: Applying options for \*  
debug2: ssh\_connect: needpriv 0  
debug1: Connecting to HOSTNAME [HOSTNAME] port 22.  
debug2: fd 3 setting O\_NONBLOCK  
debug1: connect to address HOSTNAME port 22: Connection refused  
ssh: connect to host HOSTNAME port 22: Connection refused

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/home/ubuntu/webserver.retry

webserver : ok=3 changed=0 unreachable=1 failed=0

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 24, 2014, 10:46pm UTC](https://forum.ansible.com/t/ssh-works-for-first-few-tasks-then-fails-on-different-tasks-each-attempt/16860/2 "2014-11-24T22:46:46Z")

</div>

Hmm, that’s interesting - possibly a network issue of some kind related to a router being overwhelmed or something?

---

<div class="post-metadata">

**Author:** ![David\_Whiteside](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@David\_Whiteside](https://forum.ansible.com/u/David_Whiteside)\
**Post date:** [November 24, 2014, 11:08pm UTC](https://forum.ansible.com/t/ssh-works-for-first-few-tasks-then-fails-on-different-tasks-each-attempt/16860/3 "2014-11-24T23:08:45Z")

</div>

I am connecting from a c9.io dev environment to a google compute  
server. This morning it happened much less frequently, so I believe  
you are correct. I was also able to verify it happens even when using  
ssh on the command line, so definitely environmental and not OpenSSH  
or Ansible specific.

-David
