How to use proxmox as molecule backend?

Molecule[1] is a framework designed to test ansible roles. Althought, there are a few backends natively supported by proxmox is not one of them. Thanks to “delegated” driver any backend can be used but the user needs to provide ansible playbooks responsible for creation and removal of the platform where tests run. In this post I wanted to share some details about the playbooks I developed and published on github[2].

Before you start using those you need to prepare a template on a proxmox, this basically means that a VM is installed with the operating system of choice and converted to a template. Such a template is then configured in molecule.yml as a platform, where I assume that it’s name and vmid is given. Authorization is done based on proxmox API key, which needs to be set in environment variables when the playbook runs.

The VM is cloned from the template, it’s network is then configured to a selected bridge and VM start request gets send to proxmox. We assume that quemu-guest-agent is installed on the machine and its integration is enabled on the template. Machines IP address (IPv4) is retrieved over proxmox thanks to the agent. The task is repeated until successful extraction of the address – this way we make sure that machine is not only running but also accessible over the network.

Destroy playbook is pretty obvious – it contains tasks to shutdown and destroy VMs.



[1]https://github.com/ansible-community/molecule
[2]https://github.com/cinek810/molecule-proxmox

Leave a comment