2017-07-14 16:03:45 +02:00
|
|
|
# Test code for the vmware_vm_facts module
|
2017-11-06 17:28:15 +01:00
|
|
|
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
|
2019-03-13 05:19:20 +01:00
|
|
|
# Copyright, (c) 2018, Fedor Vompe <f.vompe@comptek.ru>
|
2017-11-06 17:28:15 +01:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2017-07-14 16:03:45 +02:00
|
|
|
|
2019-05-03 05:19:02 +02:00
|
|
|
- import_role:
|
|
|
|
name: prepare_vmware_tests
|
|
|
|
vars:
|
|
|
|
setup_attach_host: true
|
|
|
|
setup_datastore: true
|
|
|
|
setup_virtualmachines: true
|
2017-08-08 15:15:51 +02:00
|
|
|
|
2019-05-11 08:26:57 +02:00
|
|
|
- &vm_data
|
|
|
|
name: Get facts about available vms
|
2017-07-14 16:03:45 +02:00
|
|
|
vmware_vm_facts:
|
|
|
|
validate_certs: false
|
2019-05-03 05:19:02 +02:00
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2017-07-14 16:03:45 +02:00
|
|
|
register: vm_facts_0001
|
|
|
|
|
2019-05-03 05:19:02 +02:00
|
|
|
- debug: var=vm_facts_0001
|
2019-05-13 20:16:10 +02:00
|
|
|
- set_fact:
|
|
|
|
first_vm: "{{ vm_facts_0001['virtual_machines'][0] }}"
|
2019-05-03 05:19:02 +02:00
|
|
|
|
2019-05-11 08:26:57 +02:00
|
|
|
- &vm_fact_check
|
|
|
|
name: Verify if VM facts exist
|
2019-02-12 12:01:42 +01:00
|
|
|
assert:
|
|
|
|
that:
|
2019-05-13 20:16:10 +02:00
|
|
|
- first_vm.esxi_hostname is defined
|
|
|
|
- first_vm.guest_fullname is defined
|
|
|
|
- first_vm.ip_address is defined
|
|
|
|
- first_vm.mac_address is defined
|
|
|
|
- first_vm.power_state is defined
|
|
|
|
- first_vm.uuid is defined
|
|
|
|
- first_vm.vm_network is defined
|
2019-02-12 12:01:42 +01:00
|
|
|
|
2019-05-11 08:26:57 +02:00
|
|
|
- <<: *vm_data
|
|
|
|
name: Get facts about available vms in check mode
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- <<: *vm_fact_check
|
|
|
|
name: Verify if VM facts exist in check mode
|
2017-07-14 16:03:45 +02:00
|
|
|
|
2019-05-11 08:26:57 +02:00
|
|
|
- name: Get folder name from VM
|
|
|
|
vmware_guest_find:
|
2019-02-12 12:01:42 +01:00
|
|
|
validate_certs: false
|
2019-05-03 05:19:02 +02:00
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2019-05-13 20:16:10 +02:00
|
|
|
name: "{{ first_vm.guest_name }}"
|
2019-05-11 08:26:57 +02:00
|
|
|
register: folder_path_info
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
folder_path: "{{ folder_path_info.folders[0] }}"
|
|
|
|
when: folder_path_info.folders is defined
|
2017-07-14 16:03:45 +02:00
|
|
|
|
2019-05-11 08:26:57 +02:00
|
|
|
- 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
|
2017-07-14 16:03:45 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2019-02-12 12:01:42 +01:00
|
|
|
- "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"
|
2017-07-14 16:03:45 +02:00
|
|
|
with_items:
|
2019-05-11 08:26:57 +02:00
|
|
|
- "{{ vm_facts.virtual_machines | json_query(query) }}"
|
2019-02-12 12:01:42 +01:00
|
|
|
vars:
|
|
|
|
query: "[?guest_name=='DC0_H0_VM0']"
|