mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
VMware: support folder param in vmware_vm_facts (#56298)
folder can be used as a filter while gathering facts about VMs. Fixes: #56125 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
setup_datastore: true
|
||||
setup_virtualmachines: true
|
||||
|
||||
|
||||
- name: Get facts about available vms
|
||||
- &vm_data
|
||||
name: Get facts about available vms
|
||||
vmware_vm_facts:
|
||||
validate_certs: false
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
@@ -21,7 +21,8 @@
|
||||
|
||||
- debug: var=vm_facts_0001
|
||||
|
||||
- name: Verify if VM facts exist
|
||||
- &vm_fact_check
|
||||
name: Verify if VM facts exist
|
||||
assert:
|
||||
that:
|
||||
- "item.esxi_hostname is defined"
|
||||
@@ -36,17 +37,37 @@
|
||||
vars:
|
||||
query: "[?guest_name=='DC0_H0_VM0']"
|
||||
|
||||
- <<: *vm_data
|
||||
name: Get facts about available vms in check mode
|
||||
check_mode: yes
|
||||
|
||||
- name: Get facts about available vms in check mode
|
||||
vmware_vm_facts:
|
||||
- <<: *vm_fact_check
|
||||
name: Verify if VM facts exist in check mode
|
||||
|
||||
- name: Get folder name from VM
|
||||
vmware_guest_find:
|
||||
validate_certs: false
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
register: vm_facts_0001
|
||||
check_mode: yes
|
||||
name: "DC0_H0_VM0"
|
||||
register: folder_path_info
|
||||
|
||||
- name: Verify if VM facts exist in check mode
|
||||
- set_fact:
|
||||
folder_path: "{{ folder_path_info.folders[0] }}"
|
||||
when: folder_path_info.folders is defined
|
||||
|
||||
- name: Gather facts about VM using folder
|
||||
vmware_vm_facts:
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
validate_certs: no
|
||||
folder: "{{ folder_path }}"
|
||||
register: vm_facts
|
||||
when: folder_path_info.folders is defined
|
||||
|
||||
- name: Check if facts are returned for VM with folder specified
|
||||
assert:
|
||||
that:
|
||||
- "item.esxi_hostname is defined"
|
||||
@@ -56,8 +77,7 @@
|
||||
- "item.power_state is defined"
|
||||
- "item.uuid is defined"
|
||||
- "item.vm_network is defined"
|
||||
- "item.attributes is defined"
|
||||
with_items:
|
||||
- "{{ vm_facts_0001.virtual_machines | json_query(query) }}"
|
||||
- "{{ vm_facts.virtual_machines | json_query(query) }}"
|
||||
vars:
|
||||
query: "[?guest_name=='DC0_H0_VM0']"
|
||||
|
||||
Reference in New Issue
Block a user