molecule
molecule copied to clipboard
Role not found when using custom `ANSIBLE_ROLES_PATH`
trafficstars
Issue Type
- Bug report
Molecule and Ansible details
$ ansible --version
ansible [core 2.14.1]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/dale/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/dale/Projects/molecule-issue/venv39/lib/python3.9/site-packages/ansible
ansible collection location = /home/dale/.ansible/collections:/usr/share/ansible/collections
executable location = /home/dale/Projects/molecule-issue/venv39/bin/ansible
python version = 3.9.16 (main, Jan 3 2023, 22:13:52) [GCC 9.4.0] (/home/dale/Projects/molecule-issue/venv39/bin/python3.9)
jinja version = 3.1.2
libyaml = True
$ molecule --version
molecule 4.0.5.dev11 using python 3.9
ansible:2.14.1
delegated:4.0.5.dev11 from molecule
docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
Molecule installation method (one of):
- pip (using
pip install git+https://github.com/ansible-community/molecule.git@main)
Ansible installation method (one of):
- pip
Detail any linters or test runners used:
- Running
moleculecommands locally from command line - see 'Actual Behaviour' section below.
Desired Behavior
Tasks from the included should be found and attempt to run.
Actual Behaviour
The included role reports as 'not found'.
# Create new directory and py39 virtualenv
$ mkdir molecule-role && cd molecule-role
$ python3.9 -m venv venv && source venv/bin/activate
# Install dependencies
$ pip install git+https://github.com/ansible-community/molecule.git@mai
$ pip install molecule-docker
# Add custom Ansible path for roles downloaded from Ansible Galaxy
$ cat ansible.cfg
[defaults]
roles_path = ./galaxy_roles
# Download an Ansible Galaxy role
# Create role and default molecult config
$ molecule init role acme.my_new_role --driver-name docker
# Edit role `tasks.yml` to run `geerlingguy.security` role
$ cat my_new_role/tasks/main.yml
---
# tasks file for my_new_role
- name: Apply `geerlingguy.security` role
ansible.builtin.include_role:
name: geerlingguy.security
$ cd my_new_role/
$ molecule --debug test
Output:
[... Lines omitted]
TASK [Include acme.my_new_role] ************************************************
TASK [Apply `geerlingguy.security` role] ***************************************
ERROR! the role 'geerlingguy.security' was not found in /home/example-user/molecule-role/my_new_role/molecule/default/roles:/home/dale/.cache/ansible-compat/b4d3f4/roles:/home/dale/.cache/molecule/my_new_role/default/roles:/home/example-user/molecule-role:/home/dale/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/example-user/molecule-role/my_new_role/molecule/default
The error appears to be in '/home/example-user/molecule-role/my_new_role/tasks/main.yml': line 5, column 11, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
ansible.builtin.include_role:
name: geerlingguy.security
^ here
Additional notes
This seems similar to https://github.com/ansible-community/molecule/issues/3404
Have you ever figured out a solution to this? I am also failing to run Molecule against a role in the same directory without first installing the role
Tried this:
provisioner:
name: ansible
ANSIBLE_ROLES_PATH: "../../"
But it does not help.
Edit: My problem was unrelated. Molecule does not consider .yaml files. Changing meta/main.yaml to meta/main.yml resolved my issue.