0

In my playbook I try to test connectivity like this:

 - name: Ensure that {{ inventory_hostname }} can reach all required ports on {{ capsule }}
  wait_for:
    host: "{{ capsule }}"
    port: "{{ item }}"
    state: started         # Port should be open
    delay: 0               # No wait before first check (sec)
    timeout: 3             # Stop checking after timeout (sec)
  ignore_errors: no
  with_items:
    - 9090 # Scap
    - 8443 # RHSM (yum)
    - 80   # Pulp
    - 443  # Pulp
    - 5000 # Pulp
    - 8140 # Puppet
    - 5647 # Qpid dispatch router
  tags:
    - checks

capsule is set earlier in the playbook with set_fact and determined by the hostname:

  - name: Check if dev node
  set_fact:
    capsule: 'sat6_cap_u'
  when: inventory_hostname is search('^[e]')
  tags:
    - prereqs

sat6_cap_u is defined in my inventory like this:

sat6_cap_u ansible_host=myhost.mydomain ansible_ssh_user=my_user

I do this to avoid repeating a "magic" hostname in my playbook. This works well when I use delegate_to: sat6_cap_u to run tasks on the capsule, but not with the wait_for module, when I run ansible-playbook with -vvv I can see that wait_for actually tries to connect to the alias instead of the real hostname:

  "module_args": {
        "active_connection_states": [
            "ESTABLISHED",
            "FIN_WAIT1",
            "FIN_WAIT2",
            "SYN_RECV",
            "SYN_SENT",
            "TIME_WAIT"
        ],
        "connect_timeout": 5,
        "delay": 0,
        "exclude_hosts": null,
        "host": "sat6_cap_u",
        "msg": null,
        "path": null,
        "port": 8140,
        "search_regex": null,
        "sleep": 1,
        "state": "started",
        "timeout": 3
    }
},
"item": 8140,
"msg": "Timeout when waiting for sat6_cap_u:8140"

Is it possible to get the real hostname from the inventory and use it with the wait_for module?

Erling
  • 11
  • 4
  • You set `capsule` to be `sat6_cap_u` and it is `sat6_cap_u` -- it is the inventory hostname -- everything seems correct except for your expectations. What's the logic of your thinking here? – techraf Sep 14 '18 at 15:36
  • I assumed that wait_for connected to the real hostname defined with ansible_host in the inventory, but sat6_cap_u is used and the connection therefore always fails. – Erling Sep 15 '18 at 09:51

0 Answers0