Q on hostvars access to inventory variables ad-hoc vs playbook

I seem to be able to query hostvars for a particular host from the command line and get at the inventory variables
but I haven’t figured out how to do this in a playbook. Might it be from hostvars being lazily loaded - or my lack of
understanding how to access hostvars inventory variables successfully (or both).

I’ve search and haven’t found anything quite this specific - or actually simple (just give me the inventory vars for this host via hostvars).

thx
jim

As an example, this works:

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

I’m trying to do this:

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:

You told ansible-playbook to use ‘prtmpftp,’ as the inventory source; this does not include any host vars, since it’s a simple comma-separated list of hostnames. You should instead use the same inventory you used in your adhoc command by running ansible-playbook hostvarstest.yml

That was it. Thanks!