I’m very new to Ansible and I have inherited some Ansible playbooks that aren’t working that I need to get working. I’ve been searching for quite some time and haven’t found any answers for this.
My current problem is that inventory_hostname is being set to localhost and I need confirmation on why. These playbooks are being used to setup the Ansible master server, and I am only running them locally.
The hostname of this machine is ansiblemaster.
I’ve created two small playbooks that reproduce the behavior I am seeing. The first one, is this
`
so lets see if this explains it:
hosts: <host pattern> reffers to groups/hostnames defined in your
inventory, Ansible always provides a definition for 'localhost' just
in case it is needed.
`inventory_hostname` is 'the name you defined in inventory', the
hostname of the machine will appear in gathered facts (several
depending on config/OS/etc) ansible_nodename, asnible_fqdn, etc. This
is not the same as hosts: , though both rely on the inventory data.
ansible_host is the variable that contains the 'actual info used to
connect to the host', which you can set in inventory or ansible will
set at each task when needed (ansible_ssh_host or ansible_winrm_host
for specific connection plugins).
None of these set the hostname for your machine (you need to use the
hostname module for that), they are just aliases/ways to refer to that
machine.