Search code examples
ansiblemolecule

How does Molecule does the role lookup


Using Molecule 2.19.0 to test it on an Ansible role. Molecule and Ansible both work as desired.

I've got a question regarding how molecule executes the Ansible role.

This is my file structure:

| my_role (Root of the role)
* defaults
* files
* molecule
   * default
       * tests
           - molecule.yml
           - playbook.yml
           - Dockerfile.j2
           - tests
* tasks
* templates

Now, in the playbook.yml of molecule I set the role name:

---
- name: Converge
  hosts: all
  roles:
    - role: my_role

When running molecule test or molecule converge, it will run the role (as expected).

But how does Molecule this under the hood? How does it know the role is present in the root directory in this particular use case.


Solution

  • Molecule does this by setting some sensible defaults for ANSIBLE_ROLES_PATH: Click me for source code

    There is also the concept of the "project directory" which is the directory that molecule is run from. This will be your role directory.