Skip to content

Commit

Permalink
Allow to provision VMs in parralel
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyr committed Oct 2, 2019
1 parent 3cc91ce commit 10489af
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 100 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,13 @@ ansible-playbook \
site.yaml
```

Use `--forks` option to controll how many VMs should be managed in parallel.


Role variables
--------------

```yaml
# Whether to show logs or not
vmware_vm_provisioning_force_show_log: no

# List of VMs to provision (see README for details)
vmware_vm_provisioning_vms: []

Expand Down
3 changes: 0 additions & 3 deletions defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---

# Whether to show logs or not
vmware_vm_provisioning_force_show_log: no

# List of VMs to provision (see README for details)
vmware_vm_provisioning_vms: []

Expand Down
101 changes: 95 additions & 6 deletions tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,97 @@
---

- name: Provision VMs
include_tasks: vm.yaml
with_items: "{{ vmware_vm_provisioning_vms | selectattr('name', 'equalto', inventory_hostname) | list }}"
loop_control:
loop_var: vm
no_log: "{{ not vmware_vm_provisioning_force_show_log }}"
- name: Set variable with VM details
set_fact:
vmware_vm_provisioning_vm: "{{ (vmware_vm_provisioning_vms | selectattr('name', 'equalto', inventory_hostname) | list)[0] }}"
when: >
vmware_vm_provisioning_vms | selectattr('name', 'equalto', inventory_hostname) | list | length > 0
- block:
- name: Power off VM
local_action:
module: vmware_guest
cluster: "{{ vmware_vm_provisioning_vm.cluster | default(vmware_vm_provisioning_cluster | default(omit)) }}"
datacenter: "{{ vmware_vm_provisioning_vm.datacenter | default(vmware_vm_provisioning_datacenter | default(omit)) }}"
esxi_hostname: "{{ vmware_vm_provisioning_vm.esxi_hostname | default(vmware_vm_provisioning_esxi_hostname | default(omit)) }}"
folder: "{{ vmware_vm_provisioning_vm.folder | default(vmware_vm_provisioning_folder | default(omit)) }}"
force: "{{ vmware_vm_provisioning_vm.force | default(vmware_vm_provisioning_force | default(omit)) }}"
hostname: "{{ vmware_vm_provisioning_vm.hostname | default(vmware_vm_provisioning_hostname | default(omit)) }}"
name: "{{ vmware_vm_provisioning_vm.name }}"
name_match: "{{ vmware_vm_provisioning_vm.name_match | default(vmware_vm_provisioning_name_match | default(omit)) }}"
password: "{{ vmware_vm_provisioning_vm.password | default(vmware_vm_provisioning_password | default(omit)) }}"
port: "{{ vmware_vm_provisioning_vm.port | default(vmware_vm_provisioning_port | default(omit)) }}"
state_change_timeout: "{{ vmware_vm_provisioning_vm.state_change_timeout | default(vmware_vm_provisioning_state_change_timeout | default(omit)) }}"
state: poweredoff
username: "{{ vmware_vm_provisioning_vm.username | default(vmware_vm_provisioning_username | default(omit)) }}"
validate_certs: "{{ vmware_vm_provisioning_vm.validate_certs | default(vmware_vm_provisioning_validate_certs | default(omit)) }}"
when: >
'state' in vmware_vm_provisioning_vm and
vmware_vm_provisioning_vm.state in ['absent', 'rebuilt']
failed_when: false

- name: Remove VM
local_action:
module: vmware_guest
cluster: "{{ vmware_vm_provisioning_vm.cluster | default(vmware_vm_provisioning_cluster | default(omit)) }}"
datacenter: "{{ vmware_vm_provisioning_vm.datacenter | default(vmware_vm_provisioning_datacenter | default(omit)) }}"
esxi_hostname: "{{ vmware_vm_provisioning_vm.esxi_hostname | default(vmware_vm_provisioning_esxi_hostname | default(omit)) }}"
folder: "{{ vmware_vm_provisioning_vm.folder | default(vmware_vm_provisioning_folder | default(omit)) }}"
force: "{{ vmware_vm_provisioning_vm.force | default(vmware_vm_provisioning_force | default(omit)) }}"
hostname: "{{ vmware_vm_provisioning_vm.hostname | default(vmware_vm_provisioning_hostname | default(omit)) }}"
name: "{{ vmware_vm_provisioning_vm.name }}"
name_match: "{{ vmware_vm_provisioning_vm.name_match | default(vmware_vm_provisioning_name_match | default(omit)) }}"
password: "{{ vmware_vm_provisioning_vm.password | default(vmware_vm_provisioning_password | default(omit)) }}"
port: "{{ vmware_vm_provisioning_vm.port | default(vmware_vm_provisioning_port | default(omit)) }}"
state_change_timeout: "{{ vmware_vm_provisioning_vm.state_change_timeout | default(vmware_vm_provisioning_state_change_timeout | default(omit)) }}"
state: absent
username: "{{ vmware_vm_provisioning_vm.username | default(vmware_vm_provisioning_username | default(omit)) }}"
validate_certs: "{{ vmware_vm_provisioning_vm.validate_certs | default(vmware_vm_provisioning_validate_certs | default(omit)) }}"
when: >
'state' in vmware_vm_provisioning_vm and
vmware_vm_provisioning_vm.state in ['absent', 'rebuilt']
- name: Provision VM
local_action:
module: vmware_guest
annotation: "{{ vmware_vm_provisioning_vm.annotation | default(vmware_vm_provisioning_annotation | default(omit)) }}"
cdrom: "{{ vmware_vm_provisioning_vm.cdrom | default(vmware_vm_provisioning_cdrom | default(omit)) }}"
cluster: "{{ vmware_vm_provisioning_vm.cluster | default(vmware_vm_provisioning_cluster | default(omit)) }}"
customization: "{{
{
'hostname': vmware_vm_provisioning_vm.name.split('.')[0],
'domain': vmware_vm_provisioning_vm.name.split('.')[1:] | join('.')
} | combine(
vmware_vm_provisioning_vm.customization | default(vmware_vm_provisioning_customization | default({}))
) }}"
customization_spec: "{{ vmware_vm_provisioning_vm.customization_spec | default(vmware_vm_provisioning_customization_spec | default(omit)) }}"
customvalues: "{{ vmware_vm_provisioning_vm.customvalues | default(vmware_vm_provisioning_customvalues | default(omit)) }}"
datacenter: "{{ vmware_vm_provisioning_vm.datacenter | default(vmware_vm_provisioning_datacenter | default(omit)) }}"
disk: "{{ vmware_vm_provisioning_vm.disks | default(vmware_vm_provisioning_disk | default(omit)) }}"
esxi_hostname: "{{ vmware_vm_provisioning_vm.esxi_hostname | default(vmware_vm_provisioning_esxi_hostname | default(omit)) }}"
folder: "{{ vmware_vm_provisioning_vm.folder | default(vmware_vm_provisioning_folder | default(omit)) }}"
force: "{{ vmware_vm_provisioning_vm.force | default(vmware_vm_provisioning_force | default(omit)) }}"
guest_id: "{{ vmware_vm_provisioning_vm.guest_id | default(vmware_vm_provisioning_guest_id | default(omit)) }}"
hardware: "{{ vmware_vm_provisioning_vm.hardware | default(vmware_vm_provisioning_hardware | default(omit)) }}"
hostname: "{{ vmware_vm_provisioning_vm.hostname | default(vmware_vm_provisioning_hostname | default(omit)) }}"
is_template: "{{ vmware_vm_provisioning_vm.is_template | default(vmware_vm_provisioning_is_template | default(omit)) }}"
linked_clone: "{{ vmware_vm_provisioning_vm.linked_clone | default(vmware_vm_provisioning_linked_clone | default(omit)) }}"
name: "{{ vmware_vm_provisioning_vm.name }}"
name_match: "{{ vmware_vm_provisioning_vm.name_match | default(vmware_vm_provisioning_name_match | default(omit)) }}"
networks: "{{ vmware_vm_provisioning_vm.networks | default(vmware_vm_provisioning_networks | default(omit)) }}"
password: "{{ vmware_vm_provisioning_vm.password | default(vmware_vm_provisioning_password | default(omit)) }}"
port: "{{ vmware_vm_provisioning_vm.port | default(vmware_vm_provisioning_port | default(omit)) }}"
resource_pool: "{{ vmware_vm_provisioning_vm.resource_pool | default(vmware_vm_provisioning_resource_pool | default(omit)) }}"
snapshot_src: "{{ vmware_vm_provisioning_vm.snapshot_src | default(vmware_vm_provisioning_snapshot_src | default(omit)) }}"
state: "{{ omit if 'state' in vmware_vm_provisioning_vm and vmware_vm_provisioning_vm.state == 'rebuilt' else vmware_vm_provisioning_vm.state | default(vmware_vm_provisioning_state | default(omit)) }}"
state_change_timeout: "{{ vmware_vm_provisioning_vm.state_change_timeout | default(vmware_vm_provisioning_state_change_timeout | default(omit)) }}"
template: "{{ vmware_vm_provisioning_vm.template | default(vmware_vm_provisioning_template | default(omit)) }}"
username: "{{ vmware_vm_provisioning_vm.username | default(vmware_vm_provisioning_username | default(omit)) }}"
uuid: "{{ vmware_vm_provisioning_vm.uuid | default(vmware_vm_provisioning_uuid | default(omit)) }}"
validate_certs: "{{ vmware_vm_provisioning_vm.validate_certs | default(vmware_vm_provisioning_validate_certs | default(omit)) }}"
vapp_properties: "{{ vmware_vm_provisioning_vm.vapp_properties | default(vmware_vm_provisioning_vapp_properties | default(omit)) }}"
wait_for_ip_address: "{{ vmware_vm_provisioning_vm.wait_for_ip_address | default(vmware_vm_provisioning_wait_for_ip_address | default(omit)) }}"
when: >
'state' not in vmware_vm_provisioning_vm or
vmware_vm_provisioning_vm.state != 'absent'
when: >
vmware_vm_provisioning_vm is defined
88 changes: 0 additions & 88 deletions tasks/vm.yaml

This file was deleted.

0 comments on commit 10489af

Please sign in to comment.