How to use VMware driver with Molecule
We needed to use the delegated driver to create a test instance if using Molecule when executing Ansible role test in VMware vSphere environment.
The create.yml and destroy.yml are necessary if we use the delegated driver, so we need to create it every time in a new role test.
I’ve looked for VMware driver because I’ve thought honestly it tiresome, but I didn’t find the driver.
So I made VMware driver of Molecule.
I will explain how to use VMware driver in this article.

molecule-vmware
The following is Molecule VMware driver by my creation.
Requirements
The molecule vmware driver requires the following.
- Python >= 3.6
- pyvmomi
- moleucle
- ansible
- VM template(linux or windows)
The driver requires the VM template to clone a test instance.
The template requires vmware tools because it is done Sysprep or Linuxprep to initialize OS.
When Linux, please also install Perl to the template.
Installation
Molecule vmware driver can install via pip.
The driver requires ansible, molecule, and pyvmomi as a dependency and Python 3.6 or more.
Please execute to install the following procedure.
pip install molecule molecule-vmware ansible pyvmomi
Please check the driver is installed.
pip show molecule-vmware
Name: molecule-vmware
Version: 0.3.0
Summary: Molecule VMware Plugin :: run molecule tests on VMware
Home-page: https://github.com/sky-joker/molecule-vmware
Author: sky-joker
Author-email: sky.jokerxx@gmail.com
License: MIT
Location: /user/dir/venv/lib/python3.6/site-packages
Requires: molecule, pyyaml
Usage
Molecule needs a role, so please create it for a test.
The following procedure is a new role creation using VMware driver.
molecule init role example -d vmware
If you want to create a scenario only, here’s.
molecule init scenario -d vmware
Need to change molecule.yml based on your environment after generating the scenario.
cd example/
vi molecule/default/molecule.yml
The following is an example configuration.
It also is possible to use the environment variables in the configuration.
---
dependency:
name: galaxy
driver:
name: vmware
vcenter_hostname: $VCSA
vcenter_username: administrator@vsphere.local
vcenter_password: $VCSA_PASS
validate_certs: false
datacenter: DC
cluster: Cluster
folder: /vm/Molecule
vm_username: root
vm_password: $VM_PASS
instance_os_type: linux
platforms:
- name: instance1
template: CentOS7_TMP
hardware:
num_cpus: 2
memory_mb: 4096
networks:
- name: VM Network
ip: 192.168.10.240
netmask: 255.255.255.0
gateway: 192.168.10.1
provisioner:
name: ansible
verifier:
name: ansible
If you want to use linked clone, please add a snapshot name on thesnapshot_src
parameter in the platforms.
By using the linked clone, it will clone faster for a test instance.
(snip)
platforms:
- name: instance1
template: CentOS7_TMP
snapshot_src: linked_clone
hardware:
num_cpus: 2
memory_mb: 4096
(snip)
Please execute the molecule test command in the role directory after the molecule.yml configuration is finished.
molecule test
If the test instance created and the connection hasn’t problem is a success.
Happy Automation!