vmware_vm_info/test: drop dep on json_query
Test refactoring to avoid dependency on `json_query`.
This commit is contained in:
parent
136b3be722
commit
0703590686
2 changed files with 52 additions and 50 deletions
|
@ -32,25 +32,25 @@
|
||||||
hostname: "{{ vcenter_hostname }}"
|
hostname: "{{ vcenter_hostname }}"
|
||||||
username: "{{ vcenter_username }}"
|
username: "{{ vcenter_username }}"
|
||||||
password: "{{ vcenter_password }}"
|
password: "{{ vcenter_password }}"
|
||||||
register: vm_facts_0001
|
register: vm_facts
|
||||||
|
|
||||||
- debug: var=vm_facts_0001
|
- &set_vm_by_name
|
||||||
|
set_fact:
|
||||||
|
vm_by_name: "{{ dict(vm_facts.virtual_machines|map(attribute='guest_name')|zip(vm_facts.virtual_machines)) }}"
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
my_vm1: "{{ vm_by_name['DC0_H0_VM1'] }}"
|
||||||
- &vm_fact_check
|
- &vm_fact_check
|
||||||
name: Verify if VM facts exist
|
name: Verify if VM facts exist
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "item.esxi_hostname is defined"
|
- "my_vm1.esxi_hostname is defined"
|
||||||
- "item.guest_fullname is defined"
|
- "my_vm1.guest_fullname is defined"
|
||||||
- "item.ip_address is defined"
|
- "my_vm1.ip_address is defined"
|
||||||
- "item.mac_address is defined"
|
- "my_vm1.mac_address is defined"
|
||||||
- "item.power_state is defined"
|
- "my_vm1.power_state is defined"
|
||||||
- "item.uuid is defined"
|
- "my_vm1.uuid is defined"
|
||||||
- "item.vm_network is defined"
|
- "my_vm1.vm_network is defined"
|
||||||
with_items:
|
|
||||||
- "{{ vm_facts_0001.virtual_machines | json_query(query) }}"
|
|
||||||
vars:
|
|
||||||
query: "[?guest_name=='DC0_H0_VM0']"
|
|
||||||
|
|
||||||
- <<: *vm_data
|
- <<: *vm_data
|
||||||
name: Get facts about available vms in check mode
|
name: Get facts about available vms in check mode
|
||||||
|
@ -83,17 +83,18 @@
|
||||||
when: folder_path_info.folders is defined
|
when: folder_path_info.folders is defined
|
||||||
- debug: var=vm_facts
|
- debug: var=vm_facts
|
||||||
|
|
||||||
|
- <<: *set_vm_by_name
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
my_vm0: "{{ vm_by_name['DC0_H0_VM0'] }}"
|
||||||
|
|
||||||
- name: Check if facts are returned for VM with folder specified
|
- name: Check if facts are returned for VM with folder specified
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "item.esxi_hostname is defined"
|
- "my_vm0.esxi_hostname is defined"
|
||||||
- "item.guest_fullname is defined"
|
- "my_vm0.guest_fullname is defined"
|
||||||
- "item.ip_address is defined"
|
- "my_vm0.ip_address is defined"
|
||||||
- "item.mac_address is defined"
|
- "my_vm0.mac_address is defined"
|
||||||
- "item.power_state is defined"
|
- "my_vm0.power_state is defined"
|
||||||
- "item.uuid is defined"
|
- "my_vm0.uuid is defined"
|
||||||
- "item.vm_network is defined"
|
- "my_vm0.vm_network is defined"
|
||||||
with_items:
|
|
||||||
- "{{ vm_facts.virtual_machines | json_query(query) }}"
|
|
||||||
vars:
|
|
||||||
query: "[?guest_name=='DC0_H0_VM0']"
|
|
||||||
|
|
|
@ -32,31 +32,31 @@
|
||||||
hostname: "{{ vcenter_hostname }}"
|
hostname: "{{ vcenter_hostname }}"
|
||||||
username: "{{ vcenter_username }}"
|
username: "{{ vcenter_username }}"
|
||||||
password: "{{ vcenter_password }}"
|
password: "{{ vcenter_password }}"
|
||||||
register: vm_info_0001
|
register: vm_info
|
||||||
|
|
||||||
- debug: var=vm_info_0001
|
- &set_vm_by_name
|
||||||
|
set_fact:
|
||||||
|
vm_by_name: "{{ dict(vm_info.virtual_machines|map(attribute='guest_name')|zip(vm_info.virtual_machines)) }}"
|
||||||
|
|
||||||
- &vm_info_check
|
- set_fact:
|
||||||
|
my_vm1: "{{ vm_by_name['DC0_H0_VM1'] }}"
|
||||||
|
- &vm_fact_check
|
||||||
name: Verify if VM info exist
|
name: Verify if VM info exist
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "item.esxi_hostname is defined"
|
- "my_vm1.esxi_hostname is defined"
|
||||||
- "item.guest_fullname is defined"
|
- "my_vm1.guest_fullname is defined"
|
||||||
- "item.ip_address is defined"
|
- "my_vm1.ip_address is defined"
|
||||||
- "item.mac_address is defined"
|
- "my_vm1.mac_address is defined"
|
||||||
- "item.power_state is defined"
|
- "my_vm1.power_state is defined"
|
||||||
- "item.uuid is defined"
|
- "my_vm1.uuid is defined"
|
||||||
- "item.vm_network is defined"
|
- "my_vm1.vm_network is defined"
|
||||||
with_items:
|
|
||||||
- "{{ vm_info_0001.virtual_machines | json_query(query) }}"
|
|
||||||
vars:
|
|
||||||
query: "[?guest_name=='DC0_H0_VM0']"
|
|
||||||
|
|
||||||
- <<: *vm_data
|
- <<: *vm_data
|
||||||
name: Get info about available vms in check mode
|
name: Get info about available vms in check mode
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
|
|
||||||
- <<: *vm_info_check
|
- <<: *vm_fact_check
|
||||||
name: Verify if VM info exist in check mode
|
name: Verify if VM info exist in check mode
|
||||||
|
|
||||||
- name: Get folder name from VM
|
- name: Get folder name from VM
|
||||||
|
@ -83,17 +83,18 @@
|
||||||
when: folder_path_info.folders is defined
|
when: folder_path_info.folders is defined
|
||||||
- debug: var=vm_info
|
- debug: var=vm_info
|
||||||
|
|
||||||
|
- <<: *set_vm_by_name
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
my_vm0: "{{ vm_by_name['DC0_H0_VM0'] }}"
|
||||||
|
|
||||||
- name: Check if info are returned for VM with folder specified
|
- name: Check if info are returned for VM with folder specified
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "item.esxi_hostname is defined"
|
- "my_vm0.esxi_hostname is defined"
|
||||||
- "item.guest_fullname is defined"
|
- "my_vm0.guest_fullname is defined"
|
||||||
- "item.ip_address is defined"
|
- "my_vm0.ip_address is defined"
|
||||||
- "item.mac_address is defined"
|
- "my_vm0.mac_address is defined"
|
||||||
- "item.power_state is defined"
|
- "my_vm0.power_state is defined"
|
||||||
- "item.uuid is defined"
|
- "my_vm0.uuid is defined"
|
||||||
- "item.vm_network is defined"
|
- "my_vm0.vm_network is defined"
|
||||||
with_items:
|
|
||||||
- "{{ vm_info.virtual_machines | json_query(query) }}"
|
|
||||||
vars:
|
|
||||||
query: "[?guest_name=='DC0_H0_VM0']"
|
|
||||||
|
|
Loading…
Reference in a new issue