You try to run a playbook that uses a role, but Ansible cannot find it. The error message says the role doesn't exist, even though you're sure you installed it. Role path issues are common, especially when working with multiple projects or team members.
Introduction
This article covers troubleshooting steps and solutions for Fix Ansible Role Not Found Error. The error typically occurs in production environments and can cause service disruptions if not addressed promptly.
Symptoms
ERROR! the role 'geerlingguy.docker' was not found in /home/user/project/roles:/home/user/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/rolesOr:
ERROR! cannot find role 'nginx' in configured role pathsSometimes you get a more specific message:
ERROR! the role 'myrole' was not found. The error appears to be in '/home/user/playbook.yml': line 5, column 7Common Causes
- Configuration misconfiguration
- Missing or incorrect credentials
- Network connectivity issues
- Version compatibility problems
- Resource exhaustion or limits
- Permission or access denied
Step-by-Step Fix
Check where Ansible is looking for roles:
```bash # Show all role paths ansible-config dump | grep -i role
# List installed roles ansible-galaxy role list
# Check specific role ansible-galaxy role list | grep nginx
# View configured paths ansible-config view | grep roles_path ```
Common Causes and Fixes
Role Not Installed
The most basic cause—you haven't installed the role yet.
Install from Ansible Galaxy:
```bash # Install a role ansible-galaxy role install geerlingguy.docker
# Install specific version ansible-galaxy role install geerlingguy.docker,v4.1.1
# Install to project directory ansible-galaxy role install geerlingguy.docker -p ./roles ```
Install from GitHub:
```bash # From a git repo ansible-galaxy role install git+https://github.com/geerlingguy/ansible-role-docker.git
# Specific branch ansible-galaxy role install git+https://github.com/user/role.git,main
# Specific tag ansible-galaxy role install git+https://github.com/user/role.git,v1.0.0 ```
Wrong Role Path
Ansible looks for roles in specific locations. If your role is elsewhere, it won't be found.
Default role paths:
- ./roles (current directory)
- ~/.ansible/roles
- /usr/share/ansible/roles
- /etc/ansible/roles
Configure custom role path:
In ansible.cfg:
``ini
[defaults]
roles_path = ./roles:./galaxy_roles:~/.ansible/roles
Specify path when installing:
ansible-galaxy role install geerlingguy.docker -p ./rolesVerify role is in the correct path:
ls -la ./roles/geerlingguy.docker/
# Should see: tasks/, defaults/, meta/, etc.Missing requirements.yml
Team members may not have installed required roles.
Create requirements.yml:
# roles/requirements.yml
- src: geerlingguy.docker
version: 4.1.1
- src: geerlingguy.nginx
version: 3.1.0
- src: https://github.com/user/custom_role.git
scm: git
version: mainInstall all roles:
ansible-galaxy role install -r roles/requirements.ymlInclude installation in playbook run:
# Install roles before running
ansible-galaxy role install -r requirements.yml && ansible-playbook site.ymlIncorrect Role Name in Playbook
The role name in your playbook must match the directory name, not the Galaxy name.
Wrong:
``yaml
- hosts: all
roles:
- geerlingguy.docker # Wrong if installed with version suffix
Check actual directory name:
ls -la ~/.ansible/roles/
# You might see: geerlingguy.docker-v4.1.1Use correct name:
- hosts: all
roles:
- geerlingguy.docker # Match the directory name exactlyOr install without version suffix:
ansible-galaxy role install geerlingguy.docker --forceRole Structure Invalid
A valid role must have the correct directory structure.
Minimum valid structure:
myrole/
├── tasks/
│ └── main.ymlCheck role structure:
ls -la ~/.ansible/roles/myrole/tasks/If tasks/main.yml is missing, the role is invalid.
Create missing structure:
mkdir -p roles/myrole/tasks
touch roles/myrole/tasks/main.ymlUsing Collections Instead of Roles
Newer Ansible uses collections instead of standalone roles.
Install a collection:
ansible-galaxy collection install community.dockerUse collection roles in playbook:
- hosts: all
roles:
- community.docker.docker_composeList collections:
ansible-galaxy collection listProject Isolation
When working on multiple projects, roles can conflict.
Use project-specific roles:
# Project structure
myproject/
├── ansible.cfg
├── roles/
│ └── requirements.yml
└── site.ymlansible.cfg:
``ini
[defaults]
roles_path = ./roles
collections_path = ./collections
Install roles in project:
cd myproject
ansible-galaxy role install -r roles/requirements.yml -p ./rolesRole Installation Best Practices
Use a requirements file:
# requirements.yml
- src: geerlingguy.docker
name: docker
version: 4.1.1
- src: geerlingguy.nginx
name: nginxVersion pinning:
Always pin versions for reproducibility:
- src: geerlingguy.docker
version: 4.1.1 # Pin to specific versionUse semantic versioning:
- src: geerlingguy.docker
version: ">=4.0.0,<5.0.0" # Allow minor/patch updatesProject-local installation:
Keep roles in the project for portability:
ansible-galaxy role install -r requirements.yml -p ./roles --forceVerification
After fixing, verify the role is available:
```bash # List all roles ansible-galaxy role list
# Check specific role exists ansible-galaxy role list | grep docker
# Validate playbook can find role ansible-playbook site.yml --syntax-check
# Run a test with the role ansible localhost -m include_role -a "name=docker" ```
Quick Checklist
- 1.Role installed?
ansible-galaxy role list | grep rolename - 2.Correct path?
ansible-config view | grep roles_path - 3.Valid structure?
ls roles/myrole/tasks/main.yml - 4.requirements.yml?
ansible-galaxy role install -r requirements.yml - 5.Correct name? Match directory name exactly
Related Articles
- [WordPress troubleshooting: Ansible Artifact Download Uses an Old Mi](ansible-artifact-download-uses-an-old-mirror-after-proxy-change)
- [WordPress troubleshooting: Ansible Audit Trail Misses Events Under ](ansible-audit-trail-misses-events-under-burst-load)
- [WordPress troubleshooting: Ansible Background Worker Gets Stuck in ](ansible-background-worker-stuck-in-a-retry-loop)
- [WordPress troubleshooting: Ansible Backup Completes but Restore Fai](ansible-backup-completes-but-restore-fails-checksum-validation)
- [WordPress troubleshooting: Ansible Batch Importer Duplicates Rows A](ansible-batch-importer-duplicates-rows-after-a-retry)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix Ansible Role Not Found Error", "description": "Learn how to fix Ansible role not found errors with proper role installation, path configuration, and requirements management.", "url": "https://www.fixwikihub.com/fix-ansible-role-not-found", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2025-11-11T23:31:37.554Z", "dateModified": "2025-11-11T23:31:37.554Z" } </script>