What is the difference between `inventory_hostname`, `ansible_hostname` and `ansible_host`?
IntermediateConceptInventory
Answer
inventory_hostname— the name of the host as written in the inventory (alias).ansible_host— the address Ansible connects to; defaults to the inventory name.ansible_hostname(oransible_facts['hostname']) — the machine's actual hostname, discovered by fact gathering.
They can all differ. A host named web1 in inventory with ansible_host=10.0.1.11 may report ip-10-0-1-11 as its real hostname. Use inventory_hostname for logic about the inventory, and facts for what the machine says about itself.
More on Inventory
What is an inventory and why does Ansible need one?BeginnerWhat are the INI and YAML inventory formats and how do they differ?BeginnerHow do you create groups of groups?BeginnerExplain host patterns: `:`, `:&`, `:!` and wildcards.IntermediateWhich connection variables can you set per host in inventory?BeginnerWhat are `group_vars` and `host_vars` directories?Intermediate