5. Writing the converge play
The converge play is a regular playbook, and you will specify in the molecule.yml
a reference to your playbook when it’s a test target.
# molecule.yml (fragment)
provisioner:
name: ansible
playbooks:
converge: ../../apache1_debian.yml
If you prefer to write your own play, create a converge.yml
file in the test scenario directory. Example of such configuration is provided in the apache4_with_role
test scenario.
# converge.yml
---
- name: Install Apache on RedHat and Debian systems (role)
hosts: webservers
become: true
roles:
- apache
Notice that in case of writing a converge.yml
play you need to take care of roles to be available for Ansible. One technique to configure the right directory is to set ENV in the provisioner
stage configuration. MOLECULE_PROJECT_DIRECTORY
contains the path level for the tested component. In case of playbooks, it’s the repo root directory; it will be a little different for role components.
# molecule.yml (fragment)
provisioner:
name: ansible
env:
ANSIBLE_ROLES_PATH: "${MOLECULE_PROJECT_DIRECTORY}/roles"
For clarity, I’ll show the converge.yml
for a play using collections. It’s the same as a role with a change in fully qualified role name, which now is explicitly taken from the myorg.unix
namespace.
# converge.yml
---
- name: Install Apache on RedHat and Debian systems (collection)
hosts: webservers
become: true
roles:
- myorg.unix.apache
Notice requirements.yml
in the test scenario directory. This file is processed by the dependency
stage to install all required collections.
# requirements.yml
---
collections:
- name: collections/ansible_collections/myorg/unix/
type: dir
The dependency stage is configured to use the requirements.yml
file by the molecule.yml
directive.
# molecule.yml (fragment)
dependency:
name: galaxy
options:
requirements-file: requirements.yml
At this stage, you understand how to prepare Molecule tests for a standalone play, play with role, and a play using a collection executing in a Podman-controlled environment. Let’s take a closer look at the assertion play.