Ansible Get vSphere Virtual Machines

Hi All,

Trying to Output only the Virtual Machine Name: but having issues with the Json output

`

Hi David,

virtual_machines is a list.
This will work:

  • debug:
    var: vminfo.virtual_machines[0].guest_name

Hi Gobi

that outputs the first on the Json List, how would i do a loop ?

i Tried with_items

 - debug:
        msg: "{{ item.tags }}"
      with_items:
        - "{{ vm_info.virtual_machines.guest_name }}"

Hi David,
You can do a loop like this

- debug:
     msg: "{{ item.tags }}"
   with_items:
     - "{{ vm_info.virtual_machines }}"

Hi Gobi,

I was using that above, but it outputs all information,
I was trying to only output the guest_name with the with_item loop

Hi David,

You can try the below loop:

  • debug:
    msg: “{{ item.guest_name }}”
    with_items:
  • “{{ vm_info.virtual_machines }}”