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.<domain>
I've created two small playbooks that reproduce the behavior I am seeing. The first one, is this
---
- hosts: ansiblemaster
tasks:
- debug: msg="{{ inventory_hostname }}"
When I run that playbook on the ansiblemaster, it works as expected and I get an output of
TASK [debug] *******************************************************************
ok: [basebox] => {
"msg": "ansiblemaster"
}
Immediately after that, I run another playbook that has this
---
- hosts: localhost
tasks:
- debug: msg="{{ inventory_hostname }}"
When I run that playbook I get
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "localhost"
}
Based on this behavior, can I assume that -hosts: localhost will always force the inventory_hostname value to localhost, regardless of what the hostname of the machine is ?