thulium_drake.vmware
Ansible Toolkit for VMWare
This toolkit helps manage VMWare clusters and includes these main features:
- Powerstate: Control the power on/off state of VMs.
- Provision Guest: Create and edit VMs and templates (some limits may apply!).
- Snap: Handle VM snapshots.
You can perform all necessary actions on a separate machine, known as the 'API host,' which can be different for each VM.
To help find VMs in your environment, there's a variable called vm_info
that contains all details about the targeted VMs, which can be useful for naming snapshots.
How to Use
This module needs the PyVmomi library and the VMWare SDK. The toolkit will automatically detect and try to install any required components.
For instructions on manual installation of dependencies, please check the example setup.
Using with RHEL 8
This toolkit works on RHEL 8, but you need to adjust the ansible_python_interpreter
based on the vSphere version:
- vSphere 7 SDK needs Python 3.3 or higher.
- vSphere 8 SDK needs Python 3.8 or higher, requiring a custom
ansible_python_interpreter
on RHEL 8.
This toolkit is set up for vSphere 7, but it hasn't been fully tested yet.
Managing Multiple vSphere Clusters
The playbook is designed to use vSphere credentials from the targeted VM's host variables. Configuring multiple VMware clusters is as simple as specifying these credentials for each host or group, just like with other variables.
When running the playbook, it gathers all necessary information for the specific VM. The required variables for each host (to be defined in 'group_vars') are:
- vsphere_api_host
- vsphere_datacenter
- vsphere_host
- vsphere_password
- vsphere_username
Powerstate Management
Supported actions include:
- Power on a VM using VMWare tools or the virtual power button.
- Power off a VM using VMWare tools or the virtual power button.
- Reboot or reset a VM using VMWare tools or the virtual power button.
The playbook does not prompt for information; it must be provided in the calling playbook:
- hosts: all
gather_facts: no
tasks:
- import_role:
name: vmware
vars:
target_action: "powerstate"
target_state: "powered-on"
run_once: yes
Required Variables for Powerstate:
target_action
: Choose from the actions provided in this toolkit.target_state
: Choose a state from the supported list.
Snapshot Management
Supported actions for snapshots include:
- Create snapshots (with a date stamp or a specified name).
- Delete specific or all snapshots.
- Revert to a specific snapshot (the script does not provide a list to choose from).
Similar to powerstate, provide the necessary information in the calling playbook:
- hosts: all
gather_facts: no
tasks:
- import_role:
name: vmware
vars:
target_action: "snap"
target_state: "present"
target_snapshot_name: ansible_snap_stuff
run_once: yes
Required Variables for Snapshots:
target_action
: Choose from the actions provided in this toolkit.target_state
: Choose an action from the supported list.
Optional Snapshot Variables:
target_snapshot_name
:- For creating snapshots: customize the snapshot name.
- For reverting/deleting: specify the target snapshot to delete.
Provisioning Guest VMs
Supported actions include:
- Create a new VM from a template or another VM.
- Delete a VM.
- Create a new template from a VM.
Information must be provided in the calling playbook, as the role will not prompt for it. A default hardware profile is available.
To create a new VM, follow these steps:
- Create a vars file with the necessary details (see documentation for the
vmware_guest
module for specifics):- Datastore
- VM folder
- Template (ensure it exists)
- Disk and controller setup
- Network setup
- RAM and CPU configuration
- VM hardware version and BIOS type
- Add a new entry to the inventory.
- Run the playbook like this:
---
- hosts: new-host.example.com
gather_facts: no
tasks:
- import_role:
name: vmware
vars:
target_action: provision_guest
target_state: present
target_esxi_hostname: esxi.example.com
run_once: yes
Required Variables for Provisioning:
target_action
: Choose from the actions provided in this toolkit.target_state
: Choose an action from the supported list.target_esxi_hostname
/target_esxi_cluster
: Name of the host/cluster for the VM.target_folder
: Folder where the VM will be placed.target_networks
: Dictionary for network configuration (seevmware_guest
documentation).target_disks
: Dictionary for disk layout (seevmware_guest
documentation).target_ram
: Dictionary for memory setup (see defaults for an example).target_cpu
: Dictionary for CPU setup (see defaults for an example).target_template
: The template to base the VM on (can be another VM or a template).
Optional Variables for Provisioning:
target_force
: Ignore warnings or errors.target_scsi
: Type of disk controller to use.target_boot_firmware
: BIOS type for the VM.target_vm_version
: VMWare hardware version to use.target_customization
: Any VMWare customization to run on the VM after creation (seevmware_guest
documentation for details).
An Ansible toolkit for VMWare
ansible-galaxy install thulium_drake.vmware