Practical Ansible Testing With Molecule
Practical Ansible Testing With Molecule
with Molecule
Fabian von Feilitzsch
Senior Software Engineer, Red Hat
Share your automation story
● Also have 3 dogs and love sci-fi (Hyperion Cantos + The Culture series are my favorites)
What’s Molecule?
Molecule Scenarios
● Contains everything necessary to test the
role in a certain way
Project structure
The playbook for running your role against the configured hosts
● Defaults to just a role import, but fully configurable
Project structure
The playbook for running your tests after playbook.yml has completed
Anatomy of a molecule.yml
Anatomy of a molecule.yml
Install dependencies
● Galaxy
● Gilt
● Shell
Anatomy of a molecule.yml
Specifies the backend
molecule will use to
provide instances
● Azure
● Delegated
● DigitalOcean
● Docker
● EC2
● GCE
● Hetzner Cloud
● Linode
● LXC
● LXD
● Openstack
● Podman
● Vagrant
Anatomy of a molecule.yml
Configure linting
● Allows override of
default linting rules
or addition of new
ones
Anatomy of a molecule.yml
Driver specific platform
configuration
● Defines instances
for molecule to
manage
● Uses Ansible
modules to handle
interactions
● Populates your
hosts
Anatomy of a molecule.yml
Configure Ansible
playbook runs
● Override playbooks
● Add group/host vars
● Set any options to
be passed to
ansible-playbook
Anatomy of a molecule.yml
Configure what to run for
tests
● Ansible (I added this!)
● Goss
● Inspec
● Testinfra
Anatomy of a molecule.yml
Configure how the scenario
runs
● Allows addition,
removal or reordering
of steps on a
per-command basis
Testing Loop
For CI/testing:
lint / dependency / cleanup / destroy / syntax / create / prepare / converge /
idempotence / side_effect / verify / cleanup / destroy
For development: