I have a problem where a playbook using add_host fails unless the host 
(which sits behind a jump server) has already been connected to by running 
another playbook.
Can anyone explain to me why the following happens, and hopefully how to 
fix it?

I have two playbooks and a hosts file:

dynamic-host.yml:

- hosts: localhost
  tasks:
    - name: add remote host
      add_host: name=remote groups=hosts

- hosts: hosts
  name: hello world
  tasks:
    - shell: echo "hello world!"

static-host.yml:

- hosts: remote
  name: hello world
  tasks:
    - shell: echo "hello world!"

hosts:

[remote]
remote ansible_host=10.0.0.1 ansible_port=22 ansible_ssh_common_args='-o 
ProxyCommand="ssh -W %h:%p -q 10.1.0.1"'

If I run the dynamic playbook, it fails:

ansible-playbook dynamic-host.yml -i hosts -vvvv
...
fatal: [remote]: UNREACHABLE! => {"changed": false, "msg": "ERROR! SSH 
encountered an unknown error. The output was:\nOpenSSH_7.2p2 
Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016\r\ndebug1: Reading 
configuration data /home/lsunde/.ssh/config\r\ndebug1: Reading 
configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 
19: Applying options for *\r\ndebug1: auto-mux: Trying existing 
master\r\ndebug1: Control socket 
\"/home/lsunde/.ansible/cp/ansible-ssh-10.0.0.1-22-lsunde\" does not 
exist\r\ndebug2: resolving \"10.0.0.1\" port 22\r\ndebug2: 
ssh_connect_direct: needpriv 0\r\ndebug1: Connecting to 10.0.0.1 [10.0.0.1] 
port 22.\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug1: connect to address 
10.0.0.1 port 22: Connection timed out\r\nssh: connect to host 10.0.0.1 
port 22: Connection timed out\r\n", "unreachable": true}

PLAY RECAP 
*********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0 
  
remote                     : ok=0    changed=0    unreachable=1    failed=0 
  

If I then run the static playbook, it succeeds:

ansible-playbook static-host.yml -i hosts -vvvv
...
PLAY RECAP 
*********************************************************************
remote                     : ok=2    changed=1    unreachable=0    failed=0 
  

If t then run the dynamic playbook again (after running the static one), it 
also succeeds:

ansible-playbook dynamic-host.yml -i hosts -vvvv
...
PLAY RECAP 
*********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0 
  
remote                     : ok=2    changed=1    unreachable=0    failed=0 
  

Any ideas why this is happening?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a82df575-bc2e-4b9c-ba02-5dc8837df286%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to