Ansible Pilot

Ansible troubleshooting - the "role not found" error

How to solve the "role not found" error using ansible-galaxy command-line utility and requirements.yml file to download and use "lucab85.ansible_role_log4shell" Ansible Role from Ansible Galaxy.

January 7, 2022
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

Today we’re going to talk about Ansible troubleshooting, specifically about the “role not found” error. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

The Best Resources For Ansible

Video Course

Books

demo

The best way of talking about Ansible troubleshooting is to jump in a live demo to show you practically the role not found errror and how to solve it!

error code

---
- name: role demo
  hosts: all
  become: true
  roles:
    - role: lucab85.ansible_role_log4shell
      detector_path: "/var"

error execution

$ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/role/role.yml 
ERROR! the role 'lucab85.ansible_role_log4shell' was not found in /Users/lberton/prj/github/ansible-pilot/troubleshooting/role/roles:/Users/lberton/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/Users/lberton/prj/github/ansible-pilot/troubleshooting/role
The error appears to be in '/Users/lberton/prj/github/ansible-pilot/troubleshooting/role/role.yml': line 6, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
    - role: lucab85.ansible_role_log4shell
      ^ here
ansible-pilot $ ls -al ~/.ansible/roles
total 0
drwxr-xr-x  2 lberton  staff   64 Jan  7 08:19 .
drwxr-xr-x  8 lberton  staff  256 Jan  7 08:19 ..
ansible-pilot $

fix code

---
roles:
  - name: lucab85.ansible_role_log4shell

fix execution

$ ansible-galaxy install -r troubleshooting/role/requirements.yml 
Starting galaxy role install process
- downloading role 'ansible_role_log4shell', owned by lucab85
- downloading role from https://github.com/lucab85/ansible-role-log4shell/archive/v0.6.1.tar.gz
- extracting lucab85.ansible_role_log4shell to /Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell
- lucab85.ansible_role_log4shell (v0.6.1) was installed successfully
ansible-pilot $ ls -al ~/.ansible/roles 
total 0
drwxr-xr-x   3 lberton  staff   96 Jan  7 08:24 .
drwxr-xr-x   8 lberton  staff  256 Jan  7 08:19 ..
drwxr-xr-x  12 lberton  staff  384 Jan  7 08:24 lucab85.ansible_role_log4shell
ansible-pilot $ ls -al ~/.ansible/roles/lucab85.ansible_role_log4shell 
total 32
drwxr-xr-x  12 lberton  staff   384 Jan  7 08:24 .
drwxr-xr-x   3 lberton  staff    96 Jan  7 08:24 ..
-rw-rw-r--   1 lberton  staff    96 Jan  6 11:22 .ansible-lint
drwxr-xr-x   5 lberton  staff   160 Jan  7 08:24 .github
-rw-rw-r--   1 lberton  staff   121 Jan  6 11:22 .yamllint
-rw-rw-r--   1 lberton  staff  1068 Jan  6 11:22 LICENSE
-rw-rw-r--   1 lberton  staff  3739 Jan  6 11:22 README.md
drwxr-xr-x   3 lberton  staff    96 Jan  7 08:24 defaults
drwxr-xr-x   4 lberton  staff   128 Jan  7 08:24 meta
drwxr-xr-x   3 lberton  staff    96 Jan  7 08:24 molecule
drwxr-xr-x   3 lberton  staff    96 Jan  7 08:24 tasks
drwxr-xr-x   3 lberton  staff    96 Jan  7 08:24 vars
ansible-pilot $ ls -al ~/.ansible/roles/lucab85.ansible_role_log4shell/*
-rw-rw-r--  1 lberton  staff  1068 Jan  6 11:22 /Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell/LICENSE
-rw-rw-r--  1 lberton  staff  3739 Jan  6 11:22 /Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell/README.md
/Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell/defaults:
total 8
drwxr-xr-x   3 lberton  staff   96 Jan  7 08:24 .
drwxr-xr-x  12 lberton  staff  384 Jan  7 08:24 ..
-rw-rw-r--   1 lberton  staff  528 Jan  6 11:22 main.yml
/Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell/meta:
total 16
drwxr-xr-x   4 lberton  staff   128 Jan  7 08:24 .
drwxr-xr-x  12 lberton  staff   384 Jan  7 08:24 ..
-rw-r--r--   1 lberton  staff    55 Jan  7 08:24 .galaxy_install_info
-rw-rw-r--   1 lberton  staff  1002 Jan  6 11:22 main.yml
/Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell/molecule:
total 0
drwxr-xr-x   3 lberton  staff   96 Jan  7 08:24 .
drwxr-xr-x  12 lberton  staff  384 Jan  7 08:24 ..
drwxr-xr-x   4 lberton  staff  128 Jan  7 08:24 default
/Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell/tasks:
total 8
drwxr-xr-x   3 lberton  staff    96 Jan  7 08:24 .
drwxr-xr-x  12 lberton  staff   384 Jan  7 08:24 ..
-rw-rw-r--   1 lberton  staff  2209 Jan  6 11:22 main.yml
/Users/lberton/.ansible/roles/lucab85.ansible_role_log4shell/vars:
total 8
drwxr-xr-x   3 lberton  staff   96 Jan  7 08:24 .
drwxr-xr-x  12 lberton  staff  384 Jan  7 08:24 ..
-rw-rw-r--   1 lberton  staff  722 Jan  6 11:22 main.yml
ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/role/role.yml
PLAY [role not found demo] ************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : print information] *****************************************
ok: [demo.example.com] => {
    "msg": "Ansible Playbook tested with detector version 1.2 released 2021-12-20.\nIf a 404 error occur please adjust the URL with the latest version available\nfor detector URL.\nPlease refer to the Red Hat Security Bullettin for up-to-date information and\nadjust the playbook variables accordingly.\nhttps://access.redhat.com/security/vulnerabilities/RHSB-2021-009.\n"
}
TASK [lucab85.ansible_role_log4shell : dependency presents] ***************************************
ok: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : create detector directory] *********************************
changed: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : download detector file] ************************************
changed: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : download detector signature] *******************************
skipping: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : gpg public key] ********************************************
skipping: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : gpg verify detector] ***************************************
skipping: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : remove any detector run directory] *************************
ok: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : create detector run directory] *****************************
changed: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : run detector/scanner] **************************************
changed: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : files in detector run directory] ***************************
ok: [demo.example.com]
TASK [lucab85.ansible_role_log4shell : print vulnerable path(s) found] ****************************
ok: [demo.example.com] => {
    "vulnerable": {
        "changed": false,
        "examined": 1,
        "failed": false,
        "files": [],
        "matched": 0,
        "msg": "All paths examined",
        "skipped_paths": {}
    }
}
TASK [lucab85.ansible_role_log4shell : remove detector directory] *********************************
changed: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com           : ok=11   changed=5    unreachable=0    failed=0    skipped=3    rescued=0    ignored=0
ansible-pilot $

code with ❤️ in GitHub

Recap

Now you know better how to troubleshoot the Ansible “role not found” error and how to fix it. Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 200+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Trustpilot
Follow me

Subscribe not to miss any new releases

FREE Top 10 Best Practices

Top 10 Best Practices of Ansible Automation: save time, reduce errors and stress