


You can also use environment variables anywhere inside the molecule.yml file, so you could have an environment variable like MOLECULE_IMAGE and specify a different OS base image whenever you do a test run, without adding additional scenarios (besides default). In many of my roles, I use a custom pre-made Docker image which already has Python and Ansible, so I removed the Dockerfile.j2 template, and updated the image in my molecule.yml to point to my public Docker Hub images. You can customize and/or remove pretty much everything.

#ANSIBLE INSTALL JAVA ON MAC VERIFICATION#
#ANSIBLE INSTALL JAVA ON MAC HOW TO#
molecule.yml: Tells molecule everything it needs to know about your testing: what OS to use, how to lint your role, how to test your role, etc.INSTALL.rst: Contains instructions for installing required dependencies for running molecule tests.The key is this makes sure important dependencies like Python, sudo, and Bash are available inside the build/test environment. You can customize it to your heart's content, and you can even use your own Docker image instead of building the container from scratch every time-I'll cover how to do that later though. Dockerfile.j2: This is the Dockerfile used to build the Docker container used as a test environment for your role.Here's a quick rundown of what all these files are: It contains the following: $ cd geerlingguy.example/molecule/default/ & ls Inside the Molecule directory is a default directory, indicating the default test scenario. This command uses ansible-galaxy behind the scenes to generate a new Ansible role, then it injects a molecule directory in the role, and sets it up to run builds and test runs in a docker environment. Installing MoleculeĪssuming you have pip installed, Installing Molecule is quite easy: pip install moleculeĬheck if it's working: $ molecule -versionīefore we start integrating Molecule into an existing role, let's take a look at the 'happy path'-using Molecule itself to init a new role: molecule init role geerlingguy.example -d docker In this blog post, I'll walk you through how to use Molecule, and how I converted all my existing roles (which were using a different testing system) to use Molecule and Ansible Lint-based tests. There was also a bit of motivation from readers of Ansible for DevOps, many of whom have asked for a new section on Molecule specifically!

After the announcement on September 26 that Ansible will be adopting molecule and ansible-lint as official 'Ansible by Red Hat' projects, I started moving more of my public Ansible projects over to Molecule-based tests instead of using the homegrown Docker-based Ansible testing rig I'd been using for a few years.
