(some stuff removed for brevity or security)
Here is my command line:
ansible-playbook playbook.yml --inventory-file dynamic_inventory.sh --limit stage --user xxx --private-key xxx.pub -e IS_VAGRANT=False -C
Here is the result of my dynamic inventory for host 'stage'
{
"hosts": [
"192.xxx.xxx.176"
],
"vars": {
}
}
Now here are the key plays, and results, from my playbook
- debug: var=vars
>> This looks pretty good (but note it doesn't show variables from my inventory)
PLAY [all] ********************************************************************
TASK: [baseUbuntu | debug var=vars] *******************************************
ok: [192.xxx.xxx.176] => {
"vars": {
"DIFFTOOL": "git --no-pager diff",
... <DELETED - but *no* HOST_NAME> ...
"IS_VAGRANT": "False",
... <DELETED - but *no* SERVER_NAME> ...
"_original_file": "/Users/xxxxxx/tmp/thissite/ansible_config/roles/baseUbuntu/tasks/main.yml",
"always_run": false,
"changed_when": null,
"delegate_to": null,
... <DELETED> ...
"role_uuid": "160302ff-f06f-4a78-8204-f0fcc4a8c750"
}
}
- debug: var=hostvars
>> This looks wrong to me. Shouldn't it either be a superset of vars and my inventory variables?
(HOST_NAME and SERVER_NAME)
TASK: [baseUbuntu | debug var=hostvars] ***************************************
ok: [192.xxx.xxx.176] => {
"hostvars": {
"192.xxx.xxx.176": {
"IS_VAGRANT": "False"
}
}
}
Hmmm... maybe I I'm not properly setting my inventory variables.
Nope! See 'HOST_NAME' is properly set. Why doesn't it show up in vars or hostvars?
- debug: msg="HOST_NAME = *{{ HOST_NAME }}*"
TASK: [baseUbuntu | debug msg="HOST_NAME = *{{ HOST_NAME }}*"] ****************
ok: [192.xxx.xxx.176] => {
}
And this one is even weirder. I use {{ HOST_NAME }} and in the "name" clause it doesn't
render and in the hostname clause it does!
- name: "Set hostname to {{ HOST_NAME }}"
hostname: name="{{ HOST_NAME }}"
TASK: [baseUbuntu | debug msg="HOST_NAME = *{{ HOST_NAME }}*"] ****************
ok: [192.xxx.xxx.176] => {
}
I'm baffled - I'd appreciate any tips. Thank you!