Interview Prep/Ansible/Roles, Collections and Galaxy

`ERROR! the role 'nginx' was not found in /home/ci/project/playbooks/roles:/home/ci/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/ci/project/playbooks`

BeginnerTroubleshootingRoles, Collections and Galaxy
Answer

Likely causes → The role was never installed in CI (requirements.yml was not run), the playbook moved into a subfolder so roles/ is no longer next to it, or roles_path in ansible.cfg is not loaded.

Diagnose → The error prints the exact search path. Run ansible --version to see which ansible.cfg is in use, and ansible-config dump | grep -i roles_path.

Fix →

# ansible.cfg at repo root
[defaults]
roles_path = ./roles:./galaxy_roles
ansible-galaxy role install -r requirements.yml -p galaxy_roles

Prevent → Pin role sources in requirements.yml, and run the install step in every pipeline or bake it into the execution environment.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Galaxy