Ansible – Access inventory alias

Question:

Having an inventory file like:

I want to gather some debug information in my templates.

  • How do I acces the alias variable in a playbook/template?
    I.e.:

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.

Answer:

The variable I was searching for is a built in feature: inventory_hostname

Ansible documentation about inventory_hostname and inventory_hostname_short is found from chapter Magic Variables, and How To Access Information About Other Hosts.

Original question: https://groups.google.com/forum/#!topic/ansible-project/Oa5YXjHecIw

Leave a Reply