-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d2dfda3
Showing
7 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Jiri Tyr 2018 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
vmware_vm_provisioning | ||
====================== | ||
|
||
Ansible role which helps to provision VMs on VMware vCenter/ESXi. | ||
|
||
The configuration of the role is done in such way that it should not be | ||
necessary to change the role for any kind of configuration. All can be | ||
done either by changing role parameters or by declaring completely new | ||
configuration as a variable. That makes this role absolutely | ||
universal. See the examples below for more details. | ||
|
||
Please report any issues or send PR. | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
```yaml | ||
--- | ||
|
||
- name: Example of how to provision VMs (all in one data structure) | ||
hosts: all | ||
vars: | ||
# List of VMs to provision | ||
vmware_vm_provisioning_vms: | ||
# Fist VM | ||
- name: test01 | ||
hostname: vcenter.example.com | ||
username: [email protected] | ||
password: p4ssw0rd | ||
validate_certs: no | ||
datacenter: DC1 | ||
cluster: Cluster1 | ||
folder: /DC1/vm | ||
disks: | ||
- size_gb: 20 | ||
autoselect_datastore: yes | ||
network: | ||
- name: VM Network | ||
ip: 192.168.1.178 | ||
netmask: 255.255.255.0 | ||
gateway: 192.168.1.1 | ||
hadrware: | ||
num_cpus: 2 | ||
memory_mb: 2048 | ||
|
||
# Second VM | ||
- name: test02 | ||
hostname: vcenter.example.com | ||
username: [email protected] | ||
password: p4ssw0rd | ||
validate_certs: no | ||
datacenter: DC2 | ||
cluster: Cluster2 | ||
folder: /DC2/vm | ||
disks: | ||
- size_gb: 20 | ||
autoselect_datastore: yes | ||
- size_gb: 500 | ||
type: thin | ||
autoselect_datastore: yes | ||
network: | ||
- name: VM Network | ||
ip: 10.0.0.178 | ||
netmask: 255.255.255.0 | ||
gateway: 10.0.0.1 | ||
hadrware: | ||
num_cpus: 2 | ||
memory_mb: 16384 | ||
roles: | ||
- vmware_vm_provisioning | ||
|
||
- name: The same like above but with reusable variables | ||
hosts: all | ||
vars: | ||
# Default login details | ||
vmware_vm_provisioning_hostname: vcenter.example.com | ||
vmware_vm_provisioning_username: [email protected] | ||
vmware_vm_provisioning_password: p4ssw0rd | ||
vmware_vm_provisioning_validate_certs: no | ||
|
||
# Disk configuration | ||
vmware_vm_provisioning_disks__default: &vmware_vm_provisioning_disks__default | ||
size_gb: 20 | ||
autoselect_datastore: yes | ||
|
||
# Network configuration for MyNET1 | ||
vmware_vm_provisioning_networks__mynet1: &vmware_vm_provisioning_networks__mynet1 | ||
- name: VM Network | ||
netmask: 255.255.255.0 | ||
gateway: 192.168.1.1 | ||
|
||
# Network configuration for MyNET1 | ||
vmware_vm_provisioning_networks__mynet1: &vmware_vm_provisioning_networks__mynet2 | ||
- name: VM Network | ||
netmask: 255.255.255.0 | ||
gateway: 10.0.0.1 | ||
|
||
# Default HW configuration | ||
vmware_vm_provisioning_hardware: &vmware_vm_provisioning_hardware | ||
num_cpus: 2 | ||
memory_mb: 2048 | ||
|
||
# Default template | ||
vmware_vm_provisioning_template: CentOS-7-1525432016 | ||
|
||
# List of VMs to provision | ||
vmware_vm_provisioning_vms: | ||
# First VM | ||
- name: test01 | ||
datacenter: DC1 | ||
cluster: Cluster1 | ||
folder: /DC1/vm | ||
networks: | ||
# Include the default network configuration | ||
- <<: *vmware_vm_provisioning_networks__mynet1 | ||
# And jsut add the IP | ||
ip: 192.168.1.178 | ||
disks: | ||
# Include the default disk configuration | ||
- <<: *vmware_vm_provisioning_disks__default | ||
|
||
# Second VM | ||
- name: test02 | ||
datacenter: DC2 | ||
cluster: Cluster2 | ||
folder: /DC2/vm | ||
networks: | ||
# Include the default network configuration | ||
- <<: *vmware_vm_provisioning_networks__mynet2 | ||
# And jsut add the IP | ||
ip: 10.0.0.178 | ||
disks: | ||
# Include the default disk configuration | ||
- <<: *vmware_vm_provisioning_disks__default | ||
# Add one more disk (500G) | ||
- size_gb: 500 | ||
type: thin | ||
autoselect_datastore: yes | ||
hardware: | ||
# Include the default hardware settings | ||
<<: *vmware_vm_provisioning_hardware | ||
# And override memory size | ||
memory_mb: 16384 | ||
# And add one more additional option | ||
nested_virt: yes | ||
roles: | ||
- vmware_vm_provisioning | ||
``` | ||
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: [] | ||
|
||
# Default values (see README for details) | ||
#vmware_vm_provisioning_annotation: null | ||
#vmware_vm_provisioning_cdrom: null | ||
#vmware_vm_provisioning_cluster: null | ||
#vmware_vm_provisioning_customization: null | ||
#vmware_vm_provisioning_customization_spec: null | ||
#vmware_vm_provisioning_customvalues: null | ||
#vmware_vm_provisioning_datacenter: null | ||
#vmware_vm_provisioning_disk: null | ||
#vmware_vm_provisioning_esxi_hostname: null | ||
#vmware_vm_provisioning_folder: null | ||
#vmware_vm_provisioning_force: null | ||
#vmware_vm_provisioning_guest_id: null | ||
#vmware_vm_provisioning_hardware: null | ||
#vmware_vm_provisioning_hostname: null | ||
#vmware_vm_provisioning_is_template: null | ||
#vmware_vm_provisioning_linked_clone: null | ||
#vmware_vm_provisioning_name_match: null | ||
#vmware_vm_provisioning_networks: null | ||
#vmware_vm_provisioning_password: null | ||
#vmware_vm_provisioning_port: null | ||
#vmware_vm_provisioning_resource_pool: null | ||
#vmware_vm_provisioning_snapshot_src: null | ||
#vmware_vm_provisioning_state_change_timeout: null | ||
#vmware_vm_provisioning_state: null | ||
#vmware_vm_provisioning_template: null | ||
#vmware_vm_provisioning_username: null | ||
#vmware_vm_provisioning_uuid: null | ||
#vmware_vm_provisioning_validate_certs: null | ||
#vmware_vm_provisioning_vapp_properties: null | ||
#vmware_vm_provisioning_wait_for_ip_address: null | ||
``` | ||
|
||
|
||
License | ||
------- | ||
|
||
MIT | ||
|
||
|
||
Author | ||
------ | ||
|
||
Jiri Tyr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
|
||
# 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: [] | ||
|
||
# Default values (see README for details) | ||
#vmware_vm_provisioning_annotation: null | ||
#vmware_vm_provisioning_cdrom: null | ||
#vmware_vm_provisioning_cluster: null | ||
#vmware_vm_provisioning_customization: null | ||
#vmware_vm_provisioning_customization_spec: null | ||
#vmware_vm_provisioning_customvalues: null | ||
#vmware_vm_provisioning_datacenter: null | ||
#vmware_vm_provisioning_disk: null | ||
#vmware_vm_provisioning_esxi_hostname: null | ||
#vmware_vm_provisioning_folder: null | ||
#vmware_vm_provisioning_force: null | ||
#vmware_vm_provisioning_guest_id: null | ||
#vmware_vm_provisioning_hardware: null | ||
#vmware_vm_provisioning_hostname: null | ||
#vmware_vm_provisioning_is_template: null | ||
#vmware_vm_provisioning_linked_clone: null | ||
#vmware_vm_provisioning_name_match: null | ||
#vmware_vm_provisioning_networks: null | ||
#vmware_vm_provisioning_password: null | ||
#vmware_vm_provisioning_port: null | ||
#vmware_vm_provisioning_resource_pool: null | ||
#vmware_vm_provisioning_snapshot_src: null | ||
#vmware_vm_provisioning_state_change_timeout: null | ||
#vmware_vm_provisioning_state: null | ||
#vmware_vm_provisioning_template: null | ||
#vmware_vm_provisioning_username: null | ||
#vmware_vm_provisioning_uuid: null | ||
#vmware_vm_provisioning_validate_certs: null | ||
#vmware_vm_provisioning_vapp_properties: null | ||
#vmware_vm_provisioning_wait_for_ip_address: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
|
||
galaxy_info: | ||
author: Jiri Tyr | ||
description: Role which helps to provision VMs on VMware vCenter/ESXi. | ||
license: MIT | ||
min_ansible_version: 2.6 | ||
platforms: | ||
- name: EL | ||
versions: | ||
- all | ||
- name: Debian | ||
versions: | ||
- all | ||
- name: Ubuntu | ||
versions: | ||
- all | ||
galaxy_tags: | ||
- system | ||
dependencies: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
|
||
- name: Provision VMs | ||
include_tasks: vm.yaml | ||
when: | ||
vmware_vm_provisioning_limit is not defined or ( | ||
vmware_vm_provisioning_limit is string and | ||
vmware_vm_provisioning_limit == vm.name | ||
) or ( | ||
vmware_vm_provisioning_limit is not string and | ||
vm.name in vmware_vm_provisioning_limit | ||
) | ||
with_items: "{{ vmware_vm_provisioning_vms }}" | ||
loop_control: | ||
loop_var: vm | ||
no_log: "{{ not vmware_vm_provisioning_force_show_log }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
|
||
- name: Power off VM ({{ vm.name }}) | ||
vmware_guest: | ||
cluster: "{{ vm.cluster | default(vmware_vm_provisioning_cluster | default(omit)) }}" | ||
datacenter: "{{ vm.datacenter | default(vmware_vm_provisioning_datacenter | default(omit)) }}" | ||
esxi_hostname: "{{ vm.esxi_hostname | default(vmware_vm_provisioning_esxi_hostname | default(omit)) }}" | ||
folder: "{{ vm.folder | default(vmware_vm_provisioning_folder | default(omit)) }}" | ||
force: "{{ vm.force | default(vmware_vm_provisioning_force | default(omit)) }}" | ||
hostname: "{{ vm.vcenter | default(vmware_vm_provisioning_hostname | default(omit)) }}" | ||
name: "{{ vm.name }}" | ||
name_match: "{{ vm.name_match | default(vmware_vm_provisioning_name_match | default(omit)) }}" | ||
password: "{{ vm.password | default(vmware_vm_provisioning_password | default(omit)) }}" | ||
port: "{{ vm.port | default(vmware_vm_provisioning_port | default(omit)) }}" | ||
state_change_timeout: "{{ vm.state_change_timeout | default(vmware_vm_provisioning_state_change_timeout | default(omit)) }}" | ||
state: poweredoff | ||
username: "{{ vm.username | default(vmware_vm_provisioning_username | default(omit)) }}" | ||
validate_certs: "{{ vm.validate_certs | default(vmware_vm_provisioning_validate_certs | default(omit)) }}" | ||
when: > | ||
'state' in vm and | ||
vm.state in ['absent', 'rebuilt'] | ||
failed_when: false | ||
|
||
- name: Remove VM ({{ vm.name }}) | ||
vmware_guest: | ||
cluster: "{{ vm.cluster | default(vmware_vm_provisioning_cluster | default(omit)) }}" | ||
datacenter: "{{ vm.datacenter | default(vmware_vm_provisioning_datacenter | default(omit)) }}" | ||
esxi_hostname: "{{ vm.esxi_hostname | default(vmware_vm_provisioning_esxi_hostname | default(omit)) }}" | ||
folder: "{{ vm.folder | default(vmware_vm_provisioning_folder | default(omit)) }}" | ||
force: "{{ vm.force | default(vmware_vm_provisioning_force | default(omit)) }}" | ||
hostname: "{{ vm.vcenter | default(vmware_vm_provisioning_hostname | default(omit)) }}" | ||
name: "{{ vm.name }}" | ||
name_match: "{{ vm.name_match | default(vmware_vm_provisioning_name_match | default(omit)) }}" | ||
password: "{{ vm.password | default(vmware_vm_provisioning_password | default(omit)) }}" | ||
port: "{{ vm.port | default(vmware_vm_provisioning_port | default(omit)) }}" | ||
state_change_timeout: "{{ vm.state_change_timeout | default(vmware_vm_provisioning_state_change_timeout | default(omit)) }}" | ||
state: absent | ||
username: "{{ vm.username | default(vmware_vm_provisioning_username | default(omit)) }}" | ||
validate_certs: "{{ vm.validate_certs | default(vmware_vm_provisioning_validate_certs | default(omit)) }}" | ||
when: > | ||
'state' in vm and | ||
vm.state in ['absent', 'rebuilt'] | ||
- name: Provision VM ({{ vm.name }}) | ||
vmware_guest: | ||
annotation: "{{ vm.annotation | default(vmware_vm_provisioning_annotation | default(omit)) }}" | ||
cdrom: "{{ vm.cdrom | default(vmware_vm_provisioning_cdrom | default(omit)) }}" | ||
cluster: "{{ vm.cluster | default(vmware_vm_provisioning_cluster | default(omit)) }}" | ||
customization: "{{ vm.customization | default(vmware_vm_provisioning_customization | default(omit)) }}" | ||
customization_spec: "{{ vm.customization_spec | default(vmware_vm_provisioning_customization_spec | default(omit)) }}" | ||
customvalues: "{{ vm.customvalues | default(vmware_vm_provisioning_customvalues | default(omit)) }}" | ||
datacenter: "{{ vm.datacenter | default(vmware_vm_provisioning_datacenter | default(omit)) }}" | ||
disk: "{{ vm.disks | default(vmware_vm_provisioning_disk | default(omit)) }}" | ||
esxi_hostname: "{{ vm.esxi_hostname | default(vmware_vm_provisioning_esxi_hostname | default(omit)) }}" | ||
folder: "{{ vm.folder | default(vmware_vm_provisioning_folder | default(omit)) }}" | ||
force: "{{ vm.force | default(vmware_vm_provisioning_force | default(omit)) }}" | ||
guest_id: "{{ vm.guest_id | default(vmware_vm_provisioning_guest_id | default(omit)) }}" | ||
hardware: "{{ vm.hardware | default(vmware_vm_provisioning_hardware | default(omit)) }}" | ||
hostname: "{{ vm.vcenter | default(vmware_vm_provisioning_hostname | default(omit)) }}" | ||
is_template: "{{ vm.is_template | default(vmware_vm_provisioning_is_template | default(omit)) }}" | ||
linked_clone: "{{ vm.linked_clone | default(vmware_vm_provisioning_linked_clone | default(omit)) }}" | ||
name: "{{ vm.name }}" | ||
name_match: "{{ vm.name_match | default(vmware_vm_provisioning_name_match | default(omit)) }}" | ||
networks: "{{ vm.networks | default(vmware_vm_provisioning_networks | default(omit)) }}" | ||
password: "{{ vm.password | default(vmware_vm_provisioning_password | default(omit)) }}" | ||
port: "{{ vm.port | default(vmware_vm_provisioning_port | default(omit)) }}" | ||
resource_pool: "{{ vm.resource_pool | default(vmware_vm_provisioning_resource_pool | default(omit)) }}" | ||
snapshot_src: "{{ vm.snapshot_src | default(vmware_vm_provisioning_snapshot_src | default(omit)) }}" | ||
state: "{{ omit if 'state' in vm and vm.state == 'rebuilt' else vm.state | default(vmware_vm_provisioning_state | default(omit)) }}" | ||
state_change_timeout: "{{ vm.state_change_timeout | default(vmware_vm_provisioning_state_change_timeout | default(omit)) }}" | ||
template: "{{ vm.template | default(vmware_vm_provisioning_template | default(omit)) }}" | ||
username: "{{ vm.username | default(vmware_vm_provisioning_username | default(omit)) }}" | ||
uuid: "{{ vm.uuid | default(vmware_vm_provisioning_uuid | default(omit)) }}" | ||
validate_certs: "{{ vm.validate_certs | default(vmware_vm_provisioning_validate_certs | default(omit)) }}" | ||
vapp_properties: "{{ vm.vapp_properties | default(vmware_vm_provisioning_vapp_properties | default(omit)) }}" | ||
wait_for_ip_address: "{{ vm.wait_for_ip_address | default(vmware_vm_provisioning_wait_for_ip_address | default(omit)) }}" |