i can't list object

11 views
Skip to first unread message

lande...@gmail.com

unread,
May 2, 2019, 2:40:29 AM5/2/19
to Ansible Project
Hi, i'm use this playbook

---
- hosts: host1
  gather_facts: false
  connection: local

  tasks:
    - name: Gather fact datastore
      vmware_datastore_facts:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        datacenter: Datacenter
        validate_certs: no
      delegate_to: localhost
      register: datastore_guest

    - debug:
        msg: "{{datastore_guest.datastores}}"
...

and the result is this:

ok: [host1] => {
    "msg": [
        {
            "accessible": true,
            "capacity": 492042190848,
            "datastore_cluster": "N/A",
            "freeSpace": 243600982016,
            "maintenanceMode": "normal",
            "multipleHostAccess": false,
            "name": "datastore1",
            "provisioned": 513138893836,
            "type": "VMFS",
            "uncommitted": 264697685004,
            "url": "ds:///vmfs/volumes/5b924bfa-d16b145b-f2fe-dc4a3e868907/"
        }
    ]
}

ok. I want the other result. In only want freeSpace part, but when im use datastore_guest.datastores.freeSpace variable the result is:

fatal: [host1]: FAILED! => {"msg": "The task includes an option with an undefine                                                                             d variable. The error was: 'list object' has no attribute 'freeSpace'\n\nThe err                                                                             or appears to have been in '/root/playbook/operations/ListVMvalues.yml': line 50                                                                             , column 7, but may\nbe elsewhere in the file depending on the exact syntax prob                                                                             lem.\n\nThe offending line appears to be:\n\n\n    - debug:\n      ^ here\n"}

What i do it?


Jean-Yves LENHOF

unread,
May 2, 2019, 7:16:53 AM5/2/19
to ansible...@googlegroups.com

datastore_guest.datastores[0].freeSpace

You should probably works a little to understand what is a list and what is a table

Regards,

lande...@gmail.com

unread,
May 2, 2019, 7:49:30 AM5/2/19
to Ansible Project
oh my god. Thank very much <3
Reply all
Reply to author
Forward
0 new messages