0
votes

I am trying to run command on remote host from another remote host using 'delegate_to' and both hosts are linux.

Connection is successful when sshing directly on each server, but not from Ansible. Here is what I have so far:

- hosts: server1
  gather_facts: no
  tasks:
    - name: test
      delegate_to: server2
      vars: 
        ansible_user: "user1"
        ansible_ssh_pass: "password"
        ansible_ssh_common_args: "-o StricHostKeyChecking=no -o ConnectTimeout=300"
      shell: "hostname"

The "server2" ip address is stored in a variable, too, within the playbook, not in the inventory. Incrementing the connection timeout doesn't work. I'm getting

[Errno 110] Connection timed out

What else should I check?

1
Are you able to connect to each individually using Ansible (e.g. ansible all -m ping) or have you just made a direct SSH connection? If so, have you checked that you are definitely using the same credentials since you seem to be setting them directly in the playbook, rather than in config files?Calum Halpin
Thanks for your response. I directly sshed on each server and pinging works. And I am using the same credentials. That's correct that I put variables into playbook directly. The "server2" is stored in a variable, too. I'm trying to run command on the remote from remote.Brooke
delegate_to doesn't mean that server1 will run the task on server2. It means the controller (your local machine) will run the task on server2 using server1's facts.Calum Halpin
I see. Thank you for your answer. Very helpful.Brooke

1 Answers

0
votes

"What else should I check?"

You should check server2 works. Put the connection attributes into the inventory.

- hosts: server2
  tasks:
    - name: test
      shell: "hostname"