I have role, role-1, I am trying to create molecule tests for, but this role is dependent on another role, role-2, located in a different directory. As part of the molecule setup of the docker container to run the tests in I have a prepare.yml file that I am trying to use to run role-2 so that the container is prepared to run role-1. Initially I had both this roles in the same location, and didn't have this issue as they were located in the same directory. But I needed to separate the code for the roles for versioning, and I'm running into problems locating role-2 for the testing. This separation is just for development and testing, the roles get installed together in the one location for deployment, so no issue there.
I've tried import_role
, include_role
, roles
in my prepare.yml
file tasks and updated the ANSIBLE_ROLES_PATH:
in the molecule.yml
file to point to the directory with role-2 and get the same error:
ERROR! the role 'role-2' was not found in ...
It lists a bunch of directories including the one set by the ANSIBLE_ROLES_PATH value, and points to the line in my prepare.yml
file with the task name: role-2
. I had thought it may have been a permissions issues, but using import_role
I could use the become: yes
and become_user: correct_user
to but get the same error.
My prepare.yml file looks like this
- name: Prepare
hosts: all
vars:
pkg_list:
- package-1
- package-2
tasks:
- name: Install packages
become: yes
package:
name: "{{ pkg_list }}"
state: present
- name: Install role-2
become: yes
become_user: correct-user
import_role:
name: role-2
Is it possible to do what I need and call a role from another location? Or is there perhaps a better way to do this?
You get error - ERROR! the role 'role-2' was not found in
look at dirs in error. You see dir with your role?
I think you should try this
import_role:
name: role/role-2