VMware: Handle duplicate VM names in vmware_vm_facts (#45412)

This fix changes facts returned from vmware_vm_facts to list of dict from
dict of dict.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde
2019-02-12 16:31:42 +05:30
committed by GitHub
parent 6d4307377f
commit fab815fc3b
3 changed files with 79 additions and 42 deletions

View File

@@ -16,6 +16,7 @@
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?cluster=2
@@ -29,8 +30,7 @@
- debug: var=vcsim_instance
# Testcase 0001: Get detail of vms from given esxi
- name: get facts about available vms
- name: Get facts about available vms
vmware_vm_facts:
validate_certs: false
hostname: "{{ vcsim }}"
@@ -38,25 +38,42 @@
password: "{{ vcsim_instance['json']['password'] }}"
register: vm_facts_0001
- debug:
msg: "{{ vm_facts_0001['virtual_machines'].keys() }}"
- name: get all VMs
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=VM
register: host_info_result
- name: verify if VM exists
- name: Verify if VM facts exist
assert:
that:
- "{{ item | basename in vm_facts_0001['virtual_machines'].keys()}}"
- "vm_facts_0001['virtual_machines'][item | basename]['cluster'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['esxi_hostname'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['guest_fullname'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['ip_address'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['mac_address'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['power_state'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['uuid'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['vm_network'] is defined"
- "item.esxi_hostname is defined"
- "item.guest_fullname is defined"
- "item.ip_address is defined"
- "item.mac_address is defined"
- "item.power_state is defined"
- "item.uuid is defined"
- "item.vm_network is defined"
with_items:
- "{{ host_info_result['json'] }}"
- "{{ vm_facts_0001.virtual_machines | json_query(query) }}"
vars:
query: "[?guest_name=='DC0_H0_VM0']"
- name: Get facts about available vms in check mode
vmware_vm_facts:
validate_certs: false
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
register: vm_facts_0001
check_mode: yes
- name: Verify if VM facts exist in check mode
assert:
that:
- "item.esxi_hostname is defined"
- "item.guest_fullname is defined"
- "item.ip_address is defined"
- "item.mac_address is defined"
- "item.power_state is defined"
- "item.uuid is defined"
- "item.vm_network is defined"
with_items:
- "{{ vm_facts_0001.virtual_machines | json_query(query) }}"
vars:
query: "[?guest_name=='DC0_H0_VM0']"