vmware_guest: enable 3 extra tests

- network_with_dvpg
- network_with_portgroup.yml
- template_d1_c1_f0.yml
This commit is contained in:
Gonéri Le Bouder 2019-07-25 16:04:00 +02:00
parent 9182d54e98
commit 93ea961205
5 changed files with 199 additions and 144 deletions

View file

@ -13,3 +13,15 @@
discovery_proto: lldp
discovery_operation: both
state: present
- name: Attach the hosts to the DVSwitch
vmware_dvs_host:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
esxi_hostname: "{{ item }}"
switch_name: '{{ dvswitch1 }}'
vmnics:
- vmnic1
state: present
with_items: "{{ esxi_hosts }}"
when: setup_attach_host is defined

View file

@ -8,6 +8,7 @@
setup_attach_host: true
setup_datacenter: true
setup_datastore: true
setup_dvswitch: true
setup_resource_pool: true
setup_virtualmachines: true

View file

@ -3,90 +3,124 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Clone from existing VM with DVPG
- name: Deploy VM from template {{ vm1 | basename }}
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ (vm1|basename).split('_')[0] }}"
state: poweredon
folder: "{{ vm1 | dirname }}"
template: "{{ vm1 | basename }}"
name: "{{ vm_name }}"
disk:
- size: 10mb
autoselect_datastore: yes
guest_id: rhel7_64guest
hardware:
memory_mb: 512
num_cpus: 1
networks:
- name: "DC0_DVPG0"
register: no_vm_result
- when: vcsim is not defined
block:
- name: create basic DVS portgroup
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
switch_name: "{{ dvswitch1 }}"
portgroup_name: DC0_DVPG0
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: present
register: dvs_pg_result_0001
- debug: var=no_vm_result
- name: Deploy VM from template
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ dc1 }}"
state: poweredon
folder: "{{ f0 }}"
template: "{{ virtual_machines[0].name }}"
name: test_vm1
disk:
- size: 10gb
autoselect_datastore: yes
guest_id: rhel7_64guest
hardware:
memory_mb: 128
num_cpus: 1
networks:
- name: DC0_DVPG0
register: no_vm_result
- debug: var=no_vm_result
- assert:
that:
- no_vm_result is changed
- assert:
that:
- "no_vm_result.changed"
# New clone with DVPG
- name: Deploy new VM with DVPG
vmware_guest:
esxi_hostname: "{{ esxi_hosts[0] }}"
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ dc1 }}"
state: poweredon
folder: "{{ f0 }}"
name: test_vm2
disk:
- size: 10gb
autoselect_datastore: yes
guest_id: rhel7_64guest
hardware:
memory_mb: 128
num_cpus: 1
networks:
- name: "DC0_DVPG0"
dvswitch_name: "{{ dvswitch1 }}"
register: no_vm_result
- debug: var=no_vm_result
- assert:
that:
- no_vm_result is changed
# New clone with DVPG
- set_fact:
vm_name: "VM_{{ 10000 | random }}"
- debug: var=vm_name
- name: Deploy new VM with DVPG
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ (vm1|basename).split('_')[0] }}"
state: poweredon
folder: "{{ vm1 | dirname }}"
name: "{{ vm_name }}"
disk:
- size: 10mb
autoselect_datastore: yes
guest_id: rhel7_64guest
hardware:
memory_mb: 512
num_cpus: 1
networks:
- name: "DC0_DVPG0"
register: no_vm_result
- debug: var=no_vm_result
- assert:
that:
- "no_vm_result.changed"
- name: Deploy same {{ vm_name }} VM again
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ (vm1|basename).split('_')[0] }}"
state: poweredon
folder: "{{ vm1 | dirname }}"
name: "{{ vm_name }}"
disk:
- size: 10mb
autoselect_datastore: yes
guest_id: rhel7_64guest
hardware:
memory_mb: 512
num_cpus: 1
networks:
- name: "DC0_DVPG0"
register: no_vm_result
- debug: var=no_vm_result
- assert:
that:
- "not no_vm_result.changed"
- name: Deploy same VM again
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
datacenter: "{{ dc1 }}"
state: poweredon
folder: "{{ f0 }}"
name: test_vm2
disk:
- size: 10gb
autoselect_datastore: yes
guest_id: rhel7_64guest
hardware:
memory_mb: 128
num_cpus: 1
networks:
- name: "DC0_DVPG0"
register: no_vm_result
- debug: var=no_vm_result
- assert:
that:
- not (no_vm_result is changed)
always:
- when: vcsim is not defined
name: Remove VM to free the portgroup
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
name: '{{ item }}'
force: yes
state: absent
with_items:
- test_vm1
- test_vm2
- when: vcsim is not defined
name: delete basic portgroup
vmware_dvs_portgroup:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
switch_name: "{{ dvswitch1 }}"
portgroup_name: DC0_DVPG0
vlan_id: 0
num_ports: 32
portgroup_type: earlyBinding
state: absent

View file

@ -2,21 +2,6 @@
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>, Tim Steinbach <tim@nequissimus.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Create dvswitch
vmware_dvswitch:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter_name: "{{ (vm1 | basename).split('_')[0] }}"
switch_name: dvSwitch
uplink_quantity: 2
discovery_proto: lldp
discovery_operation: both
mtu: 9000
state: present
register: dvswitch
- name: Add portgroup
vmware_dvs_portgroup:
validate_certs: False
@ -24,33 +9,34 @@
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
portgroup_name: "portgroup_network"
switch_name: "{{ dvswitch.switch_name }}"
switch_name: "{{ dvswitch1 }}"
vlan_id: "1"
num_ports: 2
portgroup_type: earlyBinding
state: present
register: dvsportgroup
- debug: var=dvsportgroup
- name: create new VMs with portgroup
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: new_vm_pg
name: test_vm1
guest_id: centos64Guest
datacenter: "{{ (vm1 | basename).split('_')[0] }}"
datacenter: "{{ dc1 }}"
disk:
- size: 3mb
type: thin
autoselect_datastore: yes
networks:
- name: "{{ dvsportgroup.portgroup_name }}"
- name: portgroup_network
switch_name: "{{ dvswitch1 }}"
hardware:
num_cpus: 1
memory_mb: 512
state: poweredoff
folder: "{{ vm1 | dirname }}"
folder: "{{ f0 }}"
register: vm_with_portgroup
ignore_errors: no
@ -58,4 +44,4 @@
- assert:
that:
- "vm_with_portgroup.changed"
- vm_with_portgroup is changed

View file

@ -1,15 +1,39 @@
- name: ensure that VMs are not flagged as templates
- name: Create VMs with the poweredoff state
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}"
validate_certs: no
folder: '{{ f0 }}'
name: 'test_vm1'
state: poweredoff
guest_id: debian8_64Guest
disk:
- size_gb: 1
type: thin
datastore: '{{ ds2 }}'
hardware:
memory_mb: 128
num_cpus: 1
scsi: paravirtual
cdrom:
type: iso
iso_path: "[{{ ds1 }}] fedora.iso"
networks:
- name: VM Network
- name: ensure that VM1 are not flagged as templates
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ (item|basename).split('_')[0] }}"
folder: "{{ item|dirname }}"
name: "{{ item|basename }}"
datacenter: "{{ dc1 }}"
folder: "{{ virtual_machines[1].folder }}"
name: "{{ virtual_machines[1].name }}"
state: present
is_template: False
with_items: "{{ vmlist['json'] }}"
register: no_template_initial
- debug: var=no_template_initial
@ -17,20 +41,19 @@
- name: ensure no changes were made
assert:
that:
- "no_template_initial.results|map(attribute='changed')|unique|list == [False]"
- not (no_template_initial is changed)
- name: convert all VMs to templates
- name: convert VM1 to template
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ (item|basename).split('_')[0] }}"
folder: "{{ item|dirname }}"
name: "{{ item|basename }}"
datacenter: "{{ dc1 }}"
folder: "{{ virtual_machines[1].folder }}"
name: "{{ virtual_machines[1].name }}"
state: present
is_template: True
with_items: "{{ vmlist['json'] }}"
register: convert_to_template
- debug: var=convert_to_template
@ -38,20 +61,19 @@
- name: ensure that changes were made
assert:
that:
- "convert_to_template.results|map(attribute='changed')|unique|list == [True]"
- convert_to_template is changed
- name: make double sure that all VMs are templates
- name: make double sure that VM1 is template
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ (item|basename).split('_')[0] }}"
folder: "{{ item|dirname }}"
name: "{{ item|basename }}"
datacenter: "{{ dc1 }}"
folder: "{{ virtual_machines[1].folder }}"
name: "{{ virtual_machines[1].name }}"
state: present
is_template: True
with_items: "{{ vmlist['json'] }}"
register: still_templates
- debug: var=still_templates
@ -59,25 +81,25 @@
- name: ensure that no changes were made
assert:
that:
- "still_templates.results|map(attribute='changed')|unique|list == [False]"
- not (still_templates is changed)
- name: convert all templates back to VMs
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ (item|basename).split('_')[0] }}"
folder: "{{ item|dirname }}"
name: "{{ item|basename }}"
state: present
is_template: False
with_items: "{{ vmlist['json'] }}"
register: revert_to_vm
- debug: var=revert_to_vm
- name: ensure that changes were made
assert:
that:
- "revert_to_vm.results|map(attribute='changed')|unique|list == [True]"
# To avoid the follow error of vcsim: VirtualMachine:vm-67 does not implement: MarkAsVirtualMachine
- when: vcsim is not defined
block:
- name: convert template back to VMs
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}"
folder: "{{ virtual_machines[1].folder }}"
name: "{{ virtual_machines[1].name }}"
state: present
is_template: False
register: revert_to_vm
- debug: var=revert_to_vm
- name: ensure that changes were made
assert:
that:
- revert_to_vm is changed