Hi, i use this playbook:
Hi, i use this playbook:
---
- hosts: host1
gather_facts: false
connection: localtasks:
- 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?
Hi,
Try with disk_facts.guest_disk_facts[1]instead...
Regards,
JYL
When i’m use 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”}
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
oooooooooooh goooooooooood. THANK YOU VERY MUCH <3