default/molecule.yml is the entry point for Molecule and contains the configuration for the
# molecule/default/molecule.yml --- dependency: name: galaxy driver: name: docker lint: name: yamllint platforms: - name: instance image: centos:7 provisioner: name: ansible lint: name: ansible-lint scenario: name: default verifier: name: testinfra lint: name: flake8
Understanding this file reveals a lot about how Molecule works, so it’s a good idea to step through it and give a short explanation of each item.
If your role has any dependencies, you can add a
molecule/default/requirements.yml and Molecule will automatically run
ansible-galaxy to download them on the test instance. If there is no requirements file, Molecule will simply skip this step.
dependency: name: galaxy
The driver for your infrastructure such as
docker is the default option (and best, in my opinion). This option determines how Molecule will create and connect to your instances.
driver: name: docker
Molecule will automatically run a “linter” on your role files to make sure the YAML is valid, with
yamllint being the default.
lint: name: yamllint
Molecule will create an instance for each platform in the list and test your role on each one. The configuration keys available for each item in the list will depend on the
driver chosen. By default, Molecule will create and test on a single Centos 7 instance.
platforms: - name: instance image: centos:7
Controls how Molecule provisions each instance with your role (
ansible is the only option) and provides options for an additional layer of linting for Ansible best practices with
provisioner: name: ansible lint: name: ansible-lint
Allows you to name and configure the test sequences for multiple scenarios. I won’t elaborate on scenarios now since they aren’t important for this tutorial, but know that every role will have a
scenario: name: default
Configures the test runner that Molecule uses to verify the instances after the Ansible role has been applied.
testinfra is a Python infrastructure unit testing tool and is the default test runner. There’s another
lint configuration in this section as well, which by default uses
flake8 to lint the Python test file at
verifier: name: testinfra lint: name: flake8