0% found this document useful (0 votes)
182 views22 pages

Practical Ansible Testing With Molecule

Molecule is a tool for testing Ansible roles and playbooks. It allows you to easily create local virtual infrastructure environments to test roles across different platforms. It handles common testing tasks like syntax validation, idempotence testing, and verification of role behavior. Molecule provides standardized testing infrastructure, fast development loops, and makes it simple to add continuous integration testing for Ansible roles on any platform that supports containers.

Uploaded by

Nivinitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
182 views22 pages

Practical Ansible Testing With Molecule

Molecule is a tool for testing Ansible roles and playbooks. It allows you to easily create local virtual infrastructure environments to test roles across different platforms. It handles common testing tasks like syntax validation, idempotence testing, and verification of role behavior. Molecule provides standardized testing infrastructure, fast development loops, and makes it simple to add continuous integration testing for Ansible roles on any platform that supports containers.

Uploaded by

Nivinitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Practical Ansible Testing

with Molecule
Fabian von Feilitzsch
Senior Software Engineer, Red Hat
Share your automation story

1. How did you get started with Ansible?

2. How long have you been using it?

3. What's your favorite thing to do when you Ansible?


I ...

● Work at Red Hat


● Get to work on Ansible and Kubernetes
● Focus on bridging the Ansible and Kubernetes ecosystems
● Maintain (with substantial assistance from this wonderful community) the k8s modules as well as
the Python client that backs them

● Also have 3 dogs and love sci-fi (Hyperion Cantos + The Culture series are my favorites)
What’s Molecule?

● Testing tool for Ansible


● Spearheaded by John Dewey (@retroh)
● Donated to Red Hat by Cisco last year
● Allows you to easily spin up local `infrastructure` to test your roles/playbooks
What Problem(s) does Molecule Solve?

● Standardized testing infrastructure configuration


● Fast, iterative development loops
● All-in-one, batteries included validation for syntax, style, idempotence, correctness
● Trivially add CI for your Ansible, on any platform that lets you run a container
Project structure
Project structure

Molecule Scenarios
● Contains everything necessary to test the
role in a certain way
Project structure

Molecule configuration file


● Contains the actual specific configuration for how to spin up
infrastructure, and what to run against that infrastructure
Project structure

The playbook for running your role against the configured hosts
● Defaults to just a role import, but fully configurable
Project structure

Runs before playbook.yml, for any one-time pre-configuration


● Optional
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:

dependency / create / prepare / converge


verify
Demo time!
https://github.com/fabianvf/practical-testing-with-molecule

You might also like