Use inventory_hostname instead of ansible_hostname.
It appears to me that the intention is to check if current host is the first one in the group, then I think it's best to use inventory_hostname as it will always work and also doesn't depend on gather_facts.
ansible_hostname will not work when the host as specified in inventory does not match the hostname discovered on server because of
Changes
Use
inventory_hostname
instead ofansible_hostname
.It appears to me that the intention is to check if current host is the first one in the group, then I think it's best to use
inventory_hostname
as it will always work and also doesn't depend ongather_facts
.ansible_hostname
will not work when the host as specified in inventory does not match the hostname discovered on server because of~/.ssh/config
;Linked Issues
None.