Member-only story
Demystifying 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?
Introduction
Understanding Ansible’s internal variables is crucial for effective playbook creation. In today’s episode of Ansible Pilot, I’m Luca Berton, and we’ll unravel the differences between ansible_hostname
, inventory_hostname
, and ansible_fqdn
with practical examples in Ansible Playbooks.
Decoding the Terminology
ansible_hostname and ansible_fqdn
ansible_hostname
reads the hostname from the facts collected during the gather_facts
step. It is equivalent to running uname -n
or the hostname
command-line on the target machine. Importantly, it requires gather_facts
to be enabled in your playbook for the variable to be available. This variable reflects the hostname of the target host.
ansible_fqdn
also gathers information during gather_facts
but specifically retrieves the fully qualified domain name (FQDN) of the…