Search code examples
ansibleansible-inventoryansible-facts

How to get host alias name in a variable?


In our ansible scripts we are having a variable

set_fact: Obj_prefix=smoke-{{ ansible_host }}

this fact obj_prefix long as our ansible host name is like machinename.labname.domainname .

In our inventory file , i have captured the host name as

[swarmcluster]
smaster ansible_host=swarmmaster.vlab.mycompany.com

Instead of ansible_host if i can take alias name ,then the obj_prefix variable would be short. how to get the alias name variable? Is there any variable like ansible_hostalias ?


Solution

  • The variable you are looking for is inventory_hostname_short: see the documentation.