Having an inventory file like:
[my_hosts]
my_host ansible_ssh_host=123.123.123.123
my_host2 ansible_ssh_host=234.234.234.234
I want to gather some debug information in my templates.
How do I acces the alias variable in a playbook/template? I.e.:
debug: msg=Myhost is {{ ansible_host_alias }} # Myhost is my_host # Myhost is myhost2
I tried to gather facts using ansible -m setup my_host . The variables ansible_hostname , HOSTNAME and HOST contain the machine's hostname, i.e. echo $HOSTNAME which differs from my ansible alias.
ansible_ssh_hosthas been deprecated in favour ofansible_hostin v2.0. (docs). Likewiseansible_ssh_userandansible_ssh_portto becomeansible_userandansible_port. These shorter variables are ignored, without warning, in older versions of Ansible. - Kyr