i can't list hard disk info

48 views
Skip to first unread message

lande...@gmail.com

unread,
May 2, 2019, 3:02:57 AM5/2/19
to Ansible Project
Hi, i use this playbook:

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

  tasks:

    - name: Gather disk facts from virtual machine using name
      vmware_guest_disk_facts:
        # Unirse a vsphere
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        datacenter: Datacenter
        # Para pasar por el SSH sin autenticar nada
        validate_certs: no
        # Nombre de la maquina
        name: "{{vm}}"
      delegate_to: localhost
      # Lo metemos en una variable
      register: disk_facts

    - debug:
        msg: "{{disk_facts.guest_disk_facts}}"
...

and the result is:

ok: [host1] => {
    "msg": {
        "0": {
            "backing_datastore": "datastore1",
            "backing_disk_mode": "persistent",
            "backing_eagerlyscrub": false,
            "backing_filename": "[datastore1] ANSIBLE_Centos/ANSIBLE_Centos-000003.vmdk",
            "backing_thinprovisioned": false,
            "backing_writethrough": false,
            "capacity_in_bytes": 17179869184,
            "capacity_in_kb": 16777216,
            "controller_key": 1000,
            "key": 2000,
            "label": "Hard disk 1",
            "summary": "16,777,216 KB",
            "unit_number": 0
        },
        "1": {
            "backing_datastore": "datastore1",
            "backing_disk_mode": "persistent",
            "backing_eagerlyscrub": false,
            "backing_filename": "[datastore1] ANSIBLE_Centos/ANSIBLE_Centos_3.vmdk",
            "backing_thinprovisioned": false,
            "backing_writethrough": false,
            "capacity_in_bytes": 2147483648,
            "capacity_in_kb": 2097152,
            "controller_key": 1000,
            "key": 2001,
            "label": "Hard disk 2",
            "summary": "2,097,152 KB",
            "unit_number": 1
        }
    }
}

Good, i need second ("1") hard disk info, but when im use  variable disk_facts.guest_disk_facts.1 the result is:

fatal: [host1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: dict object has no element 1\n\nThe error 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 problem.\n\nThe offending line appears to be:\n\n\n    - debug:\n      ^ here\n"}

What I do?

Jean-Yves LENHOF

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

Hi,

Try with disk_facts.guest_disk_facts[1] instead...

Regards,


JYL


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/56c12ea3-45ea-4382-8bea-b5bd4dd86662%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lande...@gmail.com

unread,
May 2, 2019, 7:17:52 AM5/2/19
to Ansible Project
When i'm use disk_facts.guest_disk_facts[1]   the result is:

Sebastian Meyer

unread,
May 2, 2019, 7:20:46 AM5/2/19
to ansible...@googlegroups.com
On 02.05.19 13:14, Jean-Yves LENHOF wrote:
>> and the result is:
>>
>> ok: [host1] => {
>> "msg": {
>> "0": {
>>     "backing_datastore": "datastore1",
[...]
>> },
>> "1": {
>>     "backing_datastore": "datastore1",
[...]
>> }
>>     }
>> }
>>
>> Good, i need second ("1") hard disk info, but when im use variable
>> disk_facts.guest_disk_facts.1 the result is:
>>
>> fatal: [host1]: FAILED! => {"msg": "The task includes an option with
>> an undefined variable. The error was: dict object has no element
>> 1\n\nThe error 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
>> problem.\n\nThe offending line appears to be:\n\n\n    - debug:\n     
>> ^ here\n"}
>>
>> What I do?
>
>
> Hi,
>
> Try with disk_facts.guest_disk_facts[1]instead...

disk_facts.guest_disk_facts.1 and disk_facts.guest_disk_facts[1]

both expect disk_facts.guest_disk_facts to be a list, but it's a dict.

You'll need disk_facts.guest_disk_facts['1']

Notice the ''.

Sebastian

--
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

lande...@gmail.com

unread,
May 2, 2019, 8:01:37 AM5/2/19
to Ansible Project
oooooooooooh goooooooooood. THANK YOU VERY MUCH <3

Reply all
Reply to author
Forward
0 new messages