# Delegate\_to is throwing error "Failed to connect to the host via ssh"

**URL:** <https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413>\
**Category:** Ansible Project\
**Created:** [January 4, 2018, 7:42am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413 "2018-01-04T07:42:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 4, 2018, 7:42am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/1 "2018-01-04T07:42:39Z")

</div>

Hi,

My hosts file:

[ebs]  
xx.xx.xx.xx

[source]  
xx.xx.xx.xx

playbook:

---

<div class="post-metadata">

**Author:** ![mkempster22uu](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mkempster22uu](https://forum.ansible.com/u/mkempster22uu)\
**Post date:** [January 4, 2018, 10:43am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/2 "2018-01-04T10:43:22Z")

</div>

Hello,

If you set your hosts to ‘source’ the playbook will only be able to be run on hosts listed under the [source] group, therefore you cant delegate to a host not in the group you’re telling it to look at

---

<div class="post-metadata">

**Author:** ![mkempster22uu](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mkempster22uu](https://forum.ansible.com/u/mkempster22uu)\
**Post date:** [January 4, 2018, 10:46am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/3 "2018-01-04T10:46:05Z")

</div>

Further Example:

Hosts file:

[group1]  
server1  
server2

[group2]  
server3  
server4

Playbook:

---

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 5, 2018, 6:57am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/4 "2018-01-05T06:57:22Z")

</div>

But, in my case what can be the value for the delegate\_to

like:  
delegate\_to: xx.xx.xx.xx # ip address ?? then it will became static .

is there any option to provide like  
delegate\_to: group2[1] ??

---

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 5, 2018, 7:04am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/5 "2018-01-05T07:04:05Z")

</div>

let us say host file look like:

[source]  
xx.xx.xx.xx  
xx.xx.xx.xx

i tried the other way like:

hosts: source[0]

---

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 5, 2018, 7:33am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/6 "2018-01-05T07:33:33Z")

</div>

by the way i tried like this:

- hosts: oraclesource[0]  
tasks:
- name: “copy file from 147 to 149 from 141”  
synchronize:  
src: /root/gopi  
dest: /root/gopi  
delegate\_to: “{{ item }}”  
with\_items:
- “{{ groups[‘oraclesource’][1] }}”

script is running but it stuck’s at:

PLAY [oraclesource[0]] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.210.8.149]

TASK [copy file from 147 to 149 from 141] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

this is where the program is being idle

---

<div class="post-metadata">

**Author:** ![mkempster22uu](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mkempster22uu](https://forum.ansible.com/u/mkempster22uu)\
**Post date:** [January 5, 2018, 8:16am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/7 "2018-01-05T08:16:59Z")

</div>

I’m not sure totally how running an inventory dynamically with a [1] etc. works.

Have you tried running that last part with a -vvvv option? It looks like its now got to the point where it knows about the host but is hanging copying the file. So your inventory should be okay if its got past there

---

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 5, 2018, 10:38am UTC](https://forum.ansible.com/t/delegate-to-is-throwing-error-failed-to-connect-to-the-host-via-ssh/26413/8 "2018-01-05T10:38:37Z")

</div>

getting this…

\<10.210.8.150\> ESTABLISH SSH CONNECTION FOR USER: root  
\<10.210.8.150\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/a26ba33a59 10.210.8.150 ‘/bin/sh -c ‘"’“‘chmod u+x /root/.ansible/tmp/ansible-tmp-1515147067.67-174395529194101/ /root/.ansible/tmp/ansible-tmp-1515147067.67-174395529194101/synchronize.py && sleep 0’”’“‘’  
\<10.210.8.150\> (0, ‘’, ‘’)  
\<10.210.8.150\> ESTABLISH SSH CONNECTION FOR USER: root  
\<10.210.8.150\> SSH: EXEC sshpass -d11 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/a26ba33a59 -tt 10.210.8.150 '/bin/sh -c '”‘"’/usr/bin/python /root/.ansible/tmp/ansible-tmp-1515147067.67-174395529194101/synchronize.py; rm -rf “/root/.ansible/tmp/ansible-tmp-1515147067.67-174395529194101/” \> /dev/null 2\>&1 && sleep 0’“'”‘’
