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:

---
# tasks file for is-veeam-backup

- name: inventory_hostname
  debug:
    var: inventory_hostname

- name: show tags
  debug:
    var: tags

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

My aim is to do something special if a specific VMware tag and/or tag 
category exists.                               

With this in _meta for the sample host (in my inventory.json from a 
vmware_inventory.py run):

      "prtmpftp": {
        "ansible_ssh_host": "prtmpftp",
        "name": "prtmpftp",
        "parent": {
          "name": "Services",
          "parent": {
            "name": "Production",
            "parent": {
              "name": "Unix"
            }
          }
        },
        "tags": {
          "Veeam_Backup": [
            "Linux_Production_Servers"
          ]
        },
        "ansible_uuid": "d930e98b-e272-40ca-af60-34cfd946d917",
        "runtime": {
          "powerstate": "poweredOn"
        },
        "config": {
          "name": "prtmpftp",
          "template": false,
          "uuid": "421c76a6-4f0e-441d-e6c5-13cafddbe1c9"
        },
        "ansible_host": "prtmpftp",
        "guest": {
          "guestid": "centos6_64Guest",
          "guestfamily": "linuxGuest",
          "gueststate": "running",
          "hostname": "prtmpftp"
        }
      },

I get this from the playbook output:

$ ansible-playbook -i prtmpftp, is-veeam-backup.yml | more

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

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

TASK [is-veeam-backup : inventory_hostname] 
******************************************************************************************************************************
ok: [prtmpftp] => {
    "inventory_hostname": "prtmpftp"
}

TASK [is-veeam-backup : show tags] 
***************************************************************************************************************************************
ok: [prtmpftp] => {
    "tags": "VARIABLE IS NOT DEFINED!"
}

TASK [is-veeam-backup : show tags] 
***************************************************************************************************************************************
ok: [prtmpftp] => {
    "hostvars[inventory_hostname]": {
        "ansible_all_ipv4_addresses": [
 
... trimmed off the rest of the facts ...

-- 
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/a7145990-994e-48c7-8d12-4ebcb7194d51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to