Let me simplify my issue. My inventory json includes the snippet above for 
a specific host. I'm looking for any vmware tags present. Ad-hoc debug 
gives this:

$ ansible prtmpftp -m debug -a "var=tags"
prtmpftp | SUCCESS => {
    "tags": {
        "Veeam_Backup": [
            "Linux_Production_Servers"
        ]
    }
}

$ ansible prtmpftp -m debug -a "var=hostvars[inventory_hostname]['tags']"
prtmpftp | SUCCESS => {
    "hostvars[inventory_hostname]['tags']": {
        "Veeam_Backup": [
            "Linux_Production_Servers"
        ]
    }
}

$ ansible prtmpftp -m debug -a 
"var=hostvars[inventory_hostname]['tags']['Veeam_Backup']"
prtmpftp | SUCCESS => {
    "hostvars[inventory_hostname]['tags']['Veeam_Backup']": [
        "Linux_Production_Servers"
    ]
}

However, in a playbook I can't reference the tags in hostvars for this host:

--
- hosts: all 

  tasks:
    - name: show tags
      debug:
        var: hostvars[inventory_hostname]['tags']

$ ansible-playbook -i prtmpftp, hostvarstest.yml

PLAY [all] 
***************************************************************************************************************************************************************

TASK [Gathering Facts] 
***************************************************************************************************************************************************
ok: [prtmpftp]

TASK [show tags] 
*********************************************************************************************************************************************************
ok: [prtmpftp] => {
    "hostvars[inventory_hostname]['tags']": "VARIABLE IS NOT DEFINED!"
}

In fact, if I dump all of hostvars via the playbook the 'tags' are not even 
there as if it isn't getting any vars from the inventory for this host.

Am I misunderstanding how inventory variables and hostvars works in a 
playbook vs ad-hoc? The documentation is not very helpful in this area.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/dab7cfe5-a68e-45d9-896c-77af9390d579%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to