Using ansible to manage RHV/oVirt

A common task most virtualization administrators will perform is installing the guest agent(s) among their guest VMs. Ansible has a nice module that allows an administrator to automate these common tasks, such as attaching/detaching a CDROM device to a VM, rebooting several VMs, etc. Combining this with ansible’s management of Windows devices and it makes it fairly trivial to automate a mass installation of guest agents in windows.

To get started with this, upload the relevant tools ISO to RHV:

# ovirt-iso-uploader upload rhv-tools-setup.iso --iso-domain=ISO
Please provide the REST API password for the admin@internal oVirt Engine user (CTRL+D to abort): 
Uploading, please wait...
INFO: Start uploading rhv-tools-setup.iso 
Uploading: [########################################] 100%
INFO: rhv-tools-setup.iso uploaded successfully

Once this ISO is present, we can use the ovirt_vms ansible module to manipulate the VMs in RHV, saving lots of manual clicking. I wrote a couple basic playbooks and inventory file for reference, just change the authentication items username/password, RHV-M hostname, and inventory to suit your environment.  From here, you can extend this and use a WinRM specific playbook to auto-install the tools by running the specific EXE file mounted on the CDROM device.

$ ansible-playbook attach-win-guest-agent.yml -i inventory -u root

PLAY [rhevm] ******************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [rhevm.ludwar.ca]

TASK [Authenticate to RHV] ****************************************************************************************************************************************************************************************
ok: [rhevm.ludwar.ca]

TASK [Attach ISO to Windows VMs] **********************************************************************************************************************************************************************************
ok: [rhevm.ludwar.ca] => (item=ad.ludwar.ca)
changed: [rhevm.ludwar.ca] => (item=windows1.ludwar.ca)
[DEPRECATION WARNING]: The 'ovirt_vms' module is being renamed 'ovirt_vm'. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

TASK [Revoke SSO token after use] *********************************************************************************************************************************************************************************
ok: [rhevm.ludwar.ca]

PLAY RECAP ********************************************************************************************************************************************************************************************************
rhevm.ludwar.ca : ok=4 changed=1 unreachable=0 failed=0

Here we have the CDROM mounted among all the Windows guests, easy to install the tooling:

RHV guest agent tools install

And detach from the environment once we’re done:

$ ansible-playbook detach-win-guest-agent.yml -i inventory -u root

PLAY [rhevm] ******************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [rhevm.ludwar.ca]

TASK [Authenticate to RHV] ****************************************************************************************************************************************************************************************
ok: [rhevm.ludwar.ca]

TASK [Detach ISO to Windows VMs] **********************************************************************************************************************************************************************************
changed: [rhevm.ludwar.ca] => (item=ad.ludwar.ca)
changed: [rhevm.ludwar.ca] => (item=windows1.ludwar.ca)
[DEPRECATION WARNING]: The 'ovirt_vms' module is being renamed 'ovirt_vm'. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

TASK [Revoke SSO token after use] *********************************************************************************************************************************************************************************
ok: [rhevm.ludwar.ca]

PLAY RECAP ********************************************************************************************************************************************************************************************************
rhevm.ludwar.ca : ok=4 changed=1 unreachable=0 failed=0