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

bash
ERROR! the role 'geerlingguy.docker' was not found in /home/user/project/roles:/home/user/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles

Or:

bash
ERROR! cannot find role 'nginx' in configured role paths

Sometimes you get a more specific message:

bash
ERROR! the role 'myrole' was not found. The error appears to be in '/home/user/playbook.yml': line 5, column 7

Common 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:

bash
ansible-galaxy role install geerlingguy.docker -p ./roles

Verify role is in the correct path:

bash
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:

yaml
# 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: main

Install all roles:

bash
ansible-galaxy role install -r roles/requirements.yml

Include installation in playbook run:

bash
# Install roles before running
ansible-galaxy role install -r requirements.yml && ansible-playbook site.yml

Incorrect 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:

bash
ls -la ~/.ansible/roles/
# You might see: geerlingguy.docker-v4.1.1

Use correct name:

yaml
- hosts: all
  roles:
    - geerlingguy.docker  # Match the directory name exactly

Or install without version suffix:

bash
ansible-galaxy role install geerlingguy.docker --force

Role Structure Invalid

A valid role must have the correct directory structure.

Minimum valid structure:

bash
myrole/
├── tasks/
│   └── main.yml

Check role structure:

bash
ls -la ~/.ansible/roles/myrole/tasks/

If tasks/main.yml is missing, the role is invalid.

Create missing structure:

bash
mkdir -p roles/myrole/tasks
touch roles/myrole/tasks/main.yml

Using Collections Instead of Roles

Newer Ansible uses collections instead of standalone roles.

Install a collection:

bash
ansible-galaxy collection install community.docker

Use collection roles in playbook:

yaml
- hosts: all
  roles:
    - community.docker.docker_compose

List collections:

bash
ansible-galaxy collection list

Project Isolation

When working on multiple projects, roles can conflict.

Use project-specific roles:

bash
# Project structure
myproject/
├── ansible.cfg
├── roles/
│   └── requirements.yml
└── site.yml

ansible.cfg: ``ini [defaults] roles_path = ./roles collections_path = ./collections

Install roles in project:

bash
cd myproject
ansible-galaxy role install -r roles/requirements.yml -p ./roles

Role Installation Best Practices

Use a requirements file:

yaml
# requirements.yml
- src: geerlingguy.docker
  name: docker
  version: 4.1.1
- src: geerlingguy.nginx
  name: nginx

Version pinning:

Always pin versions for reproducibility:

yaml
- src: geerlingguy.docker
  version: 4.1.1  # Pin to specific version

Use semantic versioning:

yaml
- src: geerlingguy.docker
  version: ">=4.0.0,<5.0.0"  # Allow minor/patch updates

Project-local installation:

Keep roles in the project for portability:

bash
ansible-galaxy role install -r requirements.yml -p ./roles --force

Verification

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. 1.Role installed? ansible-galaxy role list | grep rolename
  2. 2.Correct path? ansible-config view | grep roles_path
  3. 3.Valid structure? ls roles/myrole/tasks/main.yml
  4. 4.requirements.yml? ansible-galaxy role install -r requirements.yml
  5. 5.Correct name? Match directory name exactly
  • [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>