Member-only story

Ansible terminology — ansible_hostname vs inventory_hostname vs ansible_fqdn

What is the difference between ansible_hostname vs inventory_hostname vs ansible_fqdn in a practical example with Ansible Playbook?

Luca Berton
4 min readMar 11, 2022

What is the difference between ansible_hostname vs inventory_hostname?

These two ansible internal variables sometimes confuse one for another but they’re fundamentally different.

I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

ansible_hostname vs inventory_hostname

ansible_hostname and ansible_fqdn

Read from the target machine hostname from the facts:

  • `ansible_hostname` read the hostname from the facts collected during the `gather_facts`
  • same as the `uname -n` or `hostname` command-line
  • Need `gather_facts` enabled, otherwise the `ansible_facts` variable would be unavailable to use in your playbook
  • Same as hostname of the target host

--

--

Luca Berton
Luca Berton

Written by Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday

No responses yet