@ -1,60 +1,14 @@
- name : Wait for Flask controller to come up online
wait_for:
host : "{{ vcsim }}"
port : 5000
state : started
- name : kill vcsim
uri:
url : http://{{ vcsim }}:5000/killall
- name : start vcsim with no folders
uri:
url : http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=2&pool=2&folder=0
register : vcsim_instance
- name : Wait for Flask controller to come up online
wait_for:
host : "{{ vcsim }}"
port : 443
state : started
- name : get a list of VMS from vcsim
uri:
url : http://{{ vcsim }}:5000/govc_find?filter=VM
register : vmlist
- name : get a list of clusters from vcsim
uri:
url : http://{{ vcsim }}:5000/govc_find?filter=CCR
register : clusts
- name : get a list of resource pools from vcsim
uri:
url : http://{{ vcsim }}:5000/govc_find?filter=RP
register : res_pools
- name : get a list of hosts from vcsim
uri:
url : http://{{ vcsim }}:5000/govc_find?filter=H
register : hosts
- debug : var=vcsim_instance
- debug : var=vmlist
- debug : var=res_pools
- debug : var=clusts
- debug : var=hosts
# Create one with the defaults
# Create one with the defaults
- name : create new VM with default resource pool
- name : create new VM with default resource pool
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vcenter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vcenter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vcenter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
guest_id : centos64Guest
guest_id : centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
hardware:
hardware:
num_cpus : 1
num_cpus : 1
memory_mb : 512
memory_mb : 512
@ -63,8 +17,7 @@
type : thin
type : thin
autoselect_datastore : True
autoselect_datastore : True
state : poweredoff
state : poweredoff
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rp_d1_c1_f0
register : clone_rp_d1_c1_f0
- debug : var=clone_rp_d1_c1_f0
- debug : var=clone_rp_d1_c1_f0
@ -72,21 +25,20 @@
- name : assert that changes were made
- name : assert that changes were made
assert:
assert:
that:
that:
- "clone_rp_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]"
- clone_rp_d1_c1_f0 is changed
- name : delete the new VMs
- name : delete the new VMs
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vc enter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vc enter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vc enter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
#guest_id: centos64Guest
#guest_id: centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
state : absent
state : absent
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rp_d1_c1_f0_delete
register : clone_rp_d1_c1_f0_delete
- debug : var=clone_rp_d1_c1_f0_delete
- debug : var=clone_rp_d1_c1_f0_delete
@ -94,20 +46,20 @@
- name : assert that changes were made with deletion
- name : assert that changes were made with deletion
assert:
assert:
that:
that:
- "clone_rp_d1_c1_f0_delete.results|map(attribute='changed')|unique|list == [true]"
- clone_rp_d1_c1_f0_delete is changed
# now create with just a cluster
# now create with just a cluster
- name : create new VM with default resource pool in cluster
- name : create new VM with default resource pool in cluster
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vc enter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vc enter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vc enter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
guest_id : centos64Guest
guest_id : centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
cluster : "{{ c lusts['json'][0]|basename }}"
cluster : "{{ c cr1 }}"
hardware:
hardware:
num_cpus : 1
num_cpus : 1
memory_mb : 512
memory_mb : 512
@ -116,8 +68,7 @@
type : thin
type : thin
autoselect_datastore : True
autoselect_datastore : True
state : poweredoff
state : poweredoff
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rpc_d1_c1_f0
register : clone_rpc_d1_c1_f0
- debug : var=clone_rpc_d1_c1_f0
- debug : var=clone_rpc_d1_c1_f0
@ -125,22 +76,21 @@
- name : assert that changes were made
- name : assert that changes were made
assert:
assert:
that:
that:
- "clone_rpc_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]"
- clone_rpc_d1_c1_f0 is changed
- name : delete the new VMs
- name : delete the new VMs
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vc enter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vc enter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vc enter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
#guest_id: centos64Guest
#guest_id: centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
cluster : "{{ c lusts['json'][0]|basename }}"
cluster : "{{ c cr1 }}"
state : absent
state : absent
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rpc_d1_c1_f0_delete
register : clone_rpc_d1_c1_f0_delete
- debug : var=clone_rpc_d1_c1_f0_delete
- debug : var=clone_rpc_d1_c1_f0_delete
@ -148,21 +98,21 @@
- name : assert that changes were made with deletion
- name : assert that changes were made with deletion
assert:
assert:
that:
that:
- "clone_rpc_d1_c1_f0_delete.results|map(attribute='changed')|unique|list == [true]"
- clone_rpc_d1_c1_f0_delete is changed
# now create with a specific resource pool
# now create with a specific resource pool
- name : create new VM with specific resource pool in cluster
- name : create new VM with specific resource pool in cluster
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vc enter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vc enter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vc enter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
guest_id : centos64Guest
guest_id : centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
cluster : "{{ c lusts['json'][0]|basename }}"
cluster : "{{ c cr1 }}"
resource_pool : "{{ res_pools['json'][2]|basename }}"
resource_pool : DC0_C0_RP1
hardware:
hardware:
num_cpus : 1
num_cpus : 1
memory_mb : 512
memory_mb : 512
@ -171,8 +121,7 @@
type : thin
type : thin
autoselect_datastore : True
autoselect_datastore : True
state : poweredoff
state : poweredoff
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rpcp_d1_c1_f0
register : clone_rpcp_d1_c1_f0
- debug : var=clone_rpcp_d1_c1_f0
- debug : var=clone_rpcp_d1_c1_f0
@ -180,22 +129,21 @@
- name : assert that changes were made
- name : assert that changes were made
assert:
assert:
that:
that:
- "clone_rpcp_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]"
- clone_rpcp_d1_c1_f0 is changed
- name : delete the new VMs
- name : delete the new VMs
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vc enter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vc enter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vc enter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
#guest_id: centos64Guest
#guest_id: centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
cluster : "{{ c lusts['json'][0]|basename }}"
cluster : "{{ c cr1 }}"
state : absent
state : absent
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rpcp_d1_c1_f0_delete
register : clone_rpcp_d1_c1_f0_delete
- debug : var=clone_rpcp_d1_c1_f0_delete
- debug : var=clone_rpcp_d1_c1_f0_delete
@ -203,20 +151,20 @@
- name : assert that changes were made with deletion
- name : assert that changes were made with deletion
assert:
assert:
that:
that:
- "clone_rpcp_d1_c1_f0_delete.results|map(attribute='changed')|unique|list == [true]"
- clone_rpcp_d1_c1_f0_delete is changed
# now create with a specific host
# now create with a specific host
- name : create new VM with specific host
- name : create new VM with specific host
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vc enter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vc enter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vc enter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
guest_id : centos64Guest
guest_id : centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
esxi_hostname : "{{ hosts['json'][0]|basename }}"
esxi_hostname : '{{ hostvars[esxi1].ansible_host }}'
hardware:
hardware:
num_cpus : 1
num_cpus : 1
memory_mb : 512
memory_mb : 512
@ -225,8 +173,7 @@
type : thin
type : thin
autoselect_datastore : True
autoselect_datastore : True
state : poweredoff
state : poweredoff
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rph_d1_c1_f0
register : clone_rph_d1_c1_f0
- debug : var=clone_rph_d1_c1_f0
- debug : var=clone_rph_d1_c1_f0
@ -234,21 +181,20 @@
- name : assert that changes were made
- name : assert that changes were made
assert:
assert:
that:
that:
- "clone_rph_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]"
- clone_rph_d1_c1_f0 is changed
- name : delete the new VMs
- name : delete the new VMs
vmware_guest:
vmware_guest:
validate_certs : False
validate_certs : False
hostname : "{{ vc sim }}"
hostname : "{{ vc enter_hostname }}"
username : "{{ vc sim_instance['json']['username'] }}"
username : "{{ vc enter_username }}"
password : "{{ vc sim_instance['json']['password'] }}"
password : "{{ vc enter_password }}"
name : "{{ 'newvm_' + item|basename }}"
name : newvm_2
#template: "{{ item|basename }}"
#template: "{{ item|basename }}"
#guest_id: centos64Guest
#guest_id: centos64Guest
datacenter : "{{ (item|basename).split('_')[0] }}"
datacenter : "{{ dc1 }}"
state : absent
state : absent
folder : "{{ item|dirname }}"
folder : F0
with_items : "{{ vmlist['json'][0] }}"
register : clone_rph_d1_c1_f0_delete
register : clone_rph_d1_c1_f0_delete
- debug : var=clone_rph_d1_c1_f0_delete
- debug : var=clone_rph_d1_c1_f0_delete
@ -256,4 +202,4 @@
- name : assert that changes were made with deletion
- name : assert that changes were made with deletion
assert:
assert:
that:
that:
- "clone_rph_d1_c1_f0_delete.results|map(attribute='changed')|unique|list == [true]"
- clone_rph_d1_c1_f0_delete is changed