# Can't Fix Ansible SSH Error

**URL:** <https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132>\
**Category:** Ansible Project\
**Created:** [April 3, 2017, 8:06pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132 "2017-04-03T20:06:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [April 3, 2017, 8:06pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/1 "2017-04-03T20:06:08Z")

</div>

When I run the following Ansible playbook on my backup server, [backups.example.com](http://backups.example.com), I get the error shown below:

# main.yml

---

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [April 5, 2017, 4:55pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/2 "2017-04-05T16:55:03Z")

</div>

Here is the output when I run the playbook with the “-vvvv” argument:

PLAY [restore database server] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [fail msg=‘Please specify a database (db), -e “db=db03”’] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[db02.example.com](http://db02.example.com)]

TASK: [set\_fact db={{ db }}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\<45.56.89.116\> ESTABLISH CONNECTION FOR USER: smith  
ok: [[db02.example.com](http://db02.example.com)] =\> {“ansible\_facts”: {“db”: “db02”}}

TASK: [fail msg=‘Please specify a tier (tier), -e “tier=production”’] \*\*\*\*\*\*\*\*\*  
skipping: [[db02.example.com](http://db02.example.com)]

TASK: [set\_fact tier={{ tier }}] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\<45.56.89.116\> ESTABLISH CONNECTION FOR USER: smith  
ok: [[db02.example.com](http://db02.example.com)] =\> {“ansible\_facts”: {“tier”: “staging”}}

TASK: [rsync database backup file to database server] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\<45.56.89.116\> ESTABLISH CONNECTION FOR USER: smith  
\<45.56.89.116\> REMOTE\_MODULE command rsync -vz /srv/rsync/example.com/staging/last/database/example\_schema\_and\_data.dump  
\<45.56.89.116\> EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/smith/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 45.56.89.116 /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=asekrsupszbkgzikdiyqxqwvjazevzmq] password: " -u smith /bin/sh -c '”’“‘echo BECOME-SUCCESS-asekrsupszbkgzikdiyqxqwvjazevzmq; LANG=en\_US.UTF-8 LC\_CTYPE=en\_US.UTF-8 /usr/bin/python’”‘"’’  
fatal: [[db02.example.com](http://db02.example.com)] =\> SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/home/smith/restore\_dbserver.retry

[db02.example.com](http://db02.example.com) : ok=2 changed=0 unreachable=1 failed=0

---

<div class="post-metadata">

**Author:** ![Mark\_Phillips](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mark\_Phillips](https://forum.ansible.com/u/Mark_Phillips)\
**Post date:** [April 5, 2017, 9:02pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/3 "2017-04-05T21:02:07Z")

</div>

Hello Robert,

Does ‘ansible -m ping 45.56.89.116’ from that same backup server work just fine?

---

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [April 5, 2017, 10:19pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/4 "2017-04-05T22:19:03Z")

</div>

Hi Mark,

No, when I run the ansible ping command, I get “No hosts matched.” However, if I just use the normal ping command on that IP, I get a response.

---

<div class="post-metadata">

**Author:** ![Mark\_Phillips](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mark\_Phillips](https://forum.ansible.com/u/Mark_Phillips)\
**Post date:** [April 5, 2017, 10:26pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/5 "2017-04-05T22:26:03Z")

</div>

Hello Robert,

Ah, you’re setting that IP in the inventory file with ansible\_ssh\_host? Sorry, I didn’t notice that. Then ‘ansible -m ping whatever\_hostname\_you\_have\_in\_inventory’ (i.e. if it’s [db02.example.com](http://db02.example.com), then that name instead).

Ansible’s ‘ping’ module isn’t an ICMP ping, it’s a connectivity test – it does an SSH connection and checks things will work as expected.

You want ‘ansible -m ping \<dest\_host\>’ to work from source\_host to ensure the play will go smoothly. If that works, then we can move onto the rsync issue. Let’s prove the connectivity – from an Ansible perspective – first.

Cheers

---

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [April 5, 2017, 10:43pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/6 "2017-04-05T22:43:45Z")

</div>

Hi Mark,

Interestingly, if I ping the database server’s domain name as it’s given in the inventory file, I do get a “pong” back.

---

<div class="post-metadata">

**Author:** ![Mark\_Phillips](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mark\_Phillips](https://forum.ansible.com/u/Mark_Phillips)\
**Post date:** [April 5, 2017, 11:14pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/7 "2017-04-05T23:14:14Z")

</div>

A ha, excellent! We have some positive news 🙂

So I’d suggest there’s something up with the rsync. Wrapping rsync in Ansible can be a challenge - hence the synchronize module (also a challenge!)

I’d be inclined to just test another module between the servers too - in your playbook I mean. Maybe do something simple like a “copy” but with a small text file? If that plays ball, try the DB dump?

Is the dump file big? Would the “copy” module not suffice?

---

<div class="post-metadata">

**Author:** ![Robert\_F](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@Robert\_F](https://forum.ansible.com/u/Robert_F)\
**Post date:** [April 5, 2017, 11:45pm UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/8 "2017-04-05T23:45:41Z")

</div>

Mark,

If you can’t see anything obvious that I’m doing wrong, then that’s worth knowing. At least it rules out my doing something stupid.

Tomorrow I’ll try doing a copy and report back. I was hoping to use rsync because I have two other directories that have a lot of files, some of which will contain new files but will also contain many older files that already exist in the destination (from having been synced over the preceding day). Rsync would be perfect in this use case. But another option might be to try doing everything with Fabric instead of Ansible so I’ll investigate that too.

Thanks again for your help. I really appreciate it!

Robert

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 6, 2017, 7:01am UTC](https://forum.ansible.com/t/cant-fix-ansible-ssh-error/24132/9 "2017-04-06T07:01:49Z")

</div>

> Here is the output when I run the playbook with the "-vvvv" argument:

\<snip\>

> TASK: [rsync database backup file to database server]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> \<45.56.89.116\> ESTABLISH CONNECTION FOR USER: smith

\<snip\>

> > When I run the following Ansible playbook on my backup server,  
> > backups.example.com, I get the error shown below:
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;# main.yml  
> > &nbsp;&nbsp;&nbsp;&nbsp;---  
> > &nbsp;&nbsp;&nbsp;&nbsp;- name: restore database  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hosts: dbserver.example.com  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gather\_facts: false
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;me: smith
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- command: rsync -vz /path/to/db.dump {{ me  
> > }}@dbserver.example.com:/tmp  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become: true  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;become\_user: "{{ me }}"

You are logging in as user smith and do a sudo to user smith, why?  
Can this be the root cause of the problem?
