Hi everyone and Happy New Year 2022!
I am turning to you for a “best practice” question about inventory variables as I am experimenting w/ AWX to run our playbooks. Let me know if this is best suited for the general Ansible mailing list.
We currently have inventory variables defined as:
79 builder-11:
80 ansible_host: W.X.Y.Z
81 externalip: “{{ ansible_host }}”
82 vmid: 118300007
83 fqdn: “{{ builders_name }}1.{{ internal_domain }}”
84 hostname: “{{ builders_name }}1”
85 internalip: A.B.C.D
The inventory references certain variables like {{ internal_domain }} which are defined in a dedicated variable file (vars.yml)
We currently run our playbooks via:
ansible-playbook -i inventory/vrubiolo-test.yml playbook.yml -e @/path/to/vrubiolo-test01/vars.yml
Due to the way AWX builds inventories via ansible-inventory, I am seeing that the associated host does not have the abovementioned variables defined/resolved when looking at its entry in the AWX UI:
{
“ansible_host”: “W.X.Y.Z”,
“externalip”: “{{ ansible_host }}”,
“fqdn”: “{{ builders_name }}1.{{ internal_domain }}”,
“hostname”: “{{ builders_name }}1”,
“internalip”: “A.B.C.D”,
“vmid”: 118300007
}
This is problematic as the variables have an incorrect value.
I have also seen this behavior w/ ansible-inventory itself, when run via
ansible-inventory -i inventory/vrubiolo-test01.yaml --list -e @/path/to/vrubiolo-test01/vars.yml
I have seen related issues with ansible-inventory like https://github.com/ansible/ansible/issues/72590 but I am not sure this applies here …
Is there a way to make it so that the variables are resolved like it happens when running ansible-playbook directly?
I guess I could try to write a custom inventory plugin which would call ansible-playbook to perform the variable evaluation, parse the output and rebuild an inventory with the variables resolved but this seems overkill for what I want to do here …
Thanks for your guidance,
Vincent