mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
262 lines
7.0 KiB
YAML
262 lines
7.0 KiB
YAML
5 years ago
|
# Test code for the vmware_guest_register_operation module
|
||
|
# Copyright: (c) 2019, sky-joker <sky.jokerxx@gmail.com>
|
||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||
|
|
||
|
- import_role:
|
||
|
name: prepare_vmware_tests
|
||
|
vars:
|
||
|
setup_attach_host: true
|
||
|
setup_datastore: true
|
||
|
setup_cluster: true
|
||
|
setup_virtualmachines: true
|
||
|
setup_resource_pool: true
|
||
|
|
||
|
- block:
|
||
|
- name: gather facts of vm
|
||
|
vmware_guest_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: False
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "{{ f0 }}"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
register: vm_facts
|
||
|
|
||
|
- name: get a vm vmx file path
|
||
|
set_fact: vm_vmx_file_path="{{ vm_facts.instance.hw_files[0] }}"
|
||
|
|
||
|
- name: Powered off the vm
|
||
|
vmware_guest_powerstate:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: False
|
||
|
folder: /vm
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
state: powered-off
|
||
|
|
||
|
- name: Unregister VM from inventory
|
||
|
vmware_guest_register_operation:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
state: absent
|
||
|
|
||
|
- name: Gather all registered virtual machines
|
||
|
vmware_vm_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
register: vms
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- >-
|
||
|
vms.virtual_machines
|
||
|
| selectattr('guest_name', 'equalto', virtual_machines[0].name)
|
||
|
| map(attribute='guest_name')
|
||
|
| list
|
||
|
| length == 0
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- item.guest_name != virtual_machines[0].name
|
||
|
loop: "{{ vms.virtual_machines }}"
|
||
|
|
||
|
- name: Register VM to inventory
|
||
|
vmware_guest_register_operation:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
esxi_hostname: "{{ esxi1 }}"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
path: "{{ vm_vmx_file_path }}"
|
||
|
state: present
|
||
|
|
||
|
- name: Gather all registered virtual machines
|
||
|
vmware_vm_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
register: vms
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- >-
|
||
|
vms.virtual_machines
|
||
|
| selectattr('guest_name', 'equalto', virtual_machines[0].name)
|
||
|
| selectattr('esxi_hostname', 'equalto', esxi1)
|
||
|
| map(attribute='guest_name')
|
||
|
| list
|
||
|
| length == 1
|
||
|
|
||
|
- name: Unregister VM from inventory
|
||
|
vmware_guest_register_operation:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
state: absent
|
||
|
|
||
|
- name: Gather all registered virtual machines
|
||
|
vmware_vm_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
register: vms
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- >-
|
||
|
vms.virtual_machines
|
||
|
| selectattr('guest_name', 'equalto', virtual_machines[0].name)
|
||
|
| map(attribute='guest_name')
|
||
|
| list
|
||
|
| length == 0
|
||
|
|
||
|
- name: Register VM in Cluster
|
||
|
vmware_guest_register_operation:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
cluster: "{{ ccr1 }}"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
path: "{{ vm_vmx_file_path }}"
|
||
|
state: present
|
||
|
|
||
|
- name: Gather all registered virtual machines
|
||
|
vmware_vm_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
register: vms
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- >-
|
||
|
vms.virtual_machines
|
||
|
| selectattr('guest_name', 'equalto', virtual_machines[0].name)
|
||
|
| selectattr('cluster', 'equalto', ccr1)
|
||
|
| map(attribute='guest_name')
|
||
|
| list
|
||
|
| length == 1
|
||
|
|
||
|
- name: Unregister VM from inventory
|
||
|
vmware_guest_register_operation:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
state: absent
|
||
|
|
||
|
- name: Gather all registered virtual machines
|
||
|
vmware_vm_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
register: vms
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- >-
|
||
|
vms.virtual_machines
|
||
|
| selectattr('guest_name', 'equalto', virtual_machines[0].name)
|
||
|
| map(attribute='guest_name')
|
||
|
| list
|
||
|
| length == 0
|
||
|
|
||
|
- name: Register VM in Resource pool
|
||
|
vmware_guest_register_operation:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
resource_pool: DC0_C0_RP1
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
path: "{{ vm_vmx_file_path }}"
|
||
|
state: present
|
||
|
|
||
|
- name: Gather all registered virtual machines
|
||
|
vmware_vm_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
register: vms
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- >-
|
||
|
vms.virtual_machines
|
||
|
| selectattr('guest_name', 'equalto', virtual_machines[0].name)
|
||
|
| map(attribute='guest_name')
|
||
|
| list
|
||
|
| length == 1
|
||
|
|
||
|
- name: Gather facts of vm
|
||
|
vmware_guest_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
register: vm_facts
|
||
|
|
||
|
- name: Get a vm uuid
|
||
|
set_fact: vm_uuid="{{ vm_facts.instance.hw_product_uuid }}"
|
||
|
|
||
|
- name: Unregister VM from inventory with uuid parameter
|
||
|
vmware_guest_register_operation:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
datacenter: "{{ dc1 }}"
|
||
|
folder: "/vm"
|
||
|
name: "{{ virtual_machines[0].name }}"
|
||
|
uuid: "{{ vm_uuid }}"
|
||
|
state: absent
|
||
|
|
||
|
- name: Gather all registered virtual machines
|
||
|
vmware_vm_facts:
|
||
|
hostname: "{{ vcenter_hostname }}"
|
||
|
username: "{{ vcenter_username }}"
|
||
|
password: "{{ vcenter_password }}"
|
||
|
validate_certs: no
|
||
|
register: vms
|
||
|
|
||
|
- assert:
|
||
|
that:
|
||
|
- >-
|
||
|
vms.virtual_machines
|
||
|
| selectattr('guest_name', 'equalto', virtual_machines[0].name)
|
||
|
| map(attribute='guest_name')
|
||
|
| list
|
||
|
| length == 0
|