Delegate_to is throwing error "Failed to connect to the host via ssh"

1,224 views
Skip to first unread message

Gopi Krishna

unread,
Jan 4, 2018, 2:42:39 AM1/4/18
to Ansible Project
Hi,

My hosts file:

[ebs]
xx.xx.xx.xx

[source]
xx.xx.xx.xx

playbook:

---
- hosts: source
  tasks:
        - name: "copy file from 147 to 149 from 141"
          synchronize: 
                src:  /root/gopi
                dest: /root/gopi
          delegate_to: ebs

when im running this playbook , i am getting the below error 


TASK [copy file from 147 to 149 from 141] ********************************************************************************************
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname ebs: Name or service not known\r\n", "unreachable": true}


could somebody tell me whats wrong with the code.

Martyn Kempster

unread,
Jan 4, 2018, 5:43:23 AM1/4/18
to Ansible Project
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

Martyn Kempster

unread,
Jan 4, 2018, 5:46:05 AM1/4/18
to Ansible Project
Further Example:

Hosts file:

[group1]
server1
server2


[group2]
server3
server4


Playbook:

---
- hosts: group2
  tasks:
        - name: "copy file from 147 to 149 from 141"
          synchronize: 
                src:  /root/gopi
                dest: /root/gopi
          delegate_to: ____       <----- delegate to one of the hosts listed under group2

On Thursday, January 4, 2018 at 7:42:39 AM UTC, Gopi Krishna wrote:

Gopi Krishna

unread,
Jan 5, 2018, 1:57:22 AM1/5/18
to Ansible Project
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] ??

Gopi Krishna

unread,
Jan 5, 2018, 2:04:05 AM1/5/18
to Ansible Project
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]
   --- 
   --- code --
   ---
   delegate_to: source[1]  not working 


tried like this:

hosts: source[0]
   --- 
   --- code --
   ---
   delegate_to: "{{ groups['source'][1] }}"  not working 

how delegate it to the server 2 dynamically

On Thursday, January 4, 2018 at 1:12:39 PM UTC+5:30, Gopi Krishna wrote:

Gopi Krishna

unread,
Jan 5, 2018, 2:33:34 AM1/5/18
to Ansible Project
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 

On Thursday, January 4, 2018 at 1:12:39 PM UTC+5:30, Gopi Krishna wrote:

Martyn Kempster

unread,
Jan 5, 2018, 3:16:59 AM1/5/18
to Ansible Project
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

Gopi Krishna

unread,
Jan 5, 2018, 5:38:37 AM1/5/18
to Ansible Project
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'"'"''
Reply all
Reply to author
Forward
0 new messages