Molecule - test roles from other directory
Asked Answered
U

1

10

I want to test my roles which I have in other directory. Below my project structure: Project Structure

When I try use molecule, it can't find roles which are in roles directory.

❯ sudo molecule converge
--> Test matrix

└── default
    ├── dependency
    ├── create
    ├── prepare
    └── converge

--> Scenario: 'default'
--> Action: 'dependency'
Skipping, missing the requirements file.
Skipping, missing the requirements file.
--> Scenario: 'default'
--> Action: 'create'
Skipping, instances already created.
--> Scenario: 'default'
--> Action: 'prepare'
Skipping, prepare playbook not configured.
--> Scenario: 'default'
--> Action: 'converge'
--> Sanity checks: 'docker'
ERROR! the role 'curl' was not found in /home/belluu/programming/Ansible-Posthog/molecule/default/roles:/root/.cache/molecule/Ansible-Posthog/default/roles:/home/belluu/programming:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/belluu/programming/Ansible-Posthog/molecule/default

The error appears to be in '/home/belluu/programming/Ansible-Posthog/molecule/default/converge.yml': line 5, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  roles:
    - role: curl
      ^ here

Molecule trying find right directory but without success. Is it possible to give him path to directory with roles?

Uniplanar answered 17/5, 2020 at 18:44 Comment(0)
M
9

Simple answer: Yes

In your molecule.yml file add the following lines under env::

provisioner:
  name: ansible
  ...
  env:
    ANSIBLE_ROLES_PATH: "../../roles"

Additionally, you can link Molecule to other "paths" as well:

provisioner:
  name: ansible
  ...
  env:
    ANSIBLE_CONFIG: ../../ansible.cfg
  inventory:
    links:
      group_vars: ../../inventory/group_vars
      host_vars: ../../inventory/host_vars
Melancholic answered 6/8, 2020 at 19:37 Comment(1)
I thought their was a better answer (the bug was reporter here github.com/ansible/galaxy/issues/2030) and it stalled. If you see the related PR it is the current best approachOz

© 2022 - 2024 — McMap. All rights reserved.