What is the difference between inventory_hostname and ansible_hostname

All I could find was from the docs :

Also, inventory_hostnameis the name of the host name configured in the Ansibles inventory host file. This can be useful when you do not want to rely on the discovered hostname ansible_hostnameor for other mysterious reasons. If you have a long fully qualified domain name, it inventory_hostname_shortalso contains a part before the first period, without the rest of the domain.

Is there any actual difference between variables inventory_hostnameand ansible_hostnamein Ansible? If so, which one should I use and when?

+6
source share
1 answer
  • inventory_hostname - (: /etc/ansible/hosts). IP- , DNS
  • ansible_hostname - ansible. ssh . , , ansible_hostname.

? hostvars - , . , inventory_hostname. / , , ansible_hostname, , , IP .

. ansible_hostname, :

gather_facts: true

, ansible_hostname .

"ansible_hostname": "VARIABLE IS NOT DEFINED!"

,

  tasks:
    - debug: var=inventory_hostname
    - debug: var=ansible_hostname
    - debug: var=hostvars
+10

All Articles