Keerthy
Keerthy

Reputation: 41

Ansible roles throwing error @/root/roles:/root:/etc/ansible/roles

I am new to Ansible and I have created my first Ansible role playbook and when I tried to run it it is throwing the error below, whereas other modules apart from the roles (like handler, templates) are working fine. I am observing this issue only with the roles in the playbook.

---
- hosts: webservers
  roles:
    - nginx
ERROR! the role 'nginx' was not found in /root/roles:/root:/etc/ansible/roles

The error appears to have been in '/root/server.yml': line 4, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  roles:
    - nginx
      ^ here

In the ansible.cng file I have specified the path as roles_path = /etc/ansible/roles

Kindly let me know if I am missing anything here.

Upvotes: 3

Views: 3007

Answers (1)

Nelson G.
Nelson G.

Reputation: 5441

Because Ansible not found nginx role in folders /root/roles, /root, /etc/ansible/roles or local ./roles.

If you want to use a role named nginx, ansible will try to load a file nginx/tasks/main.yml in one of your roles folders.

Copy into your nginx role folder this code : https://github.com/jdauphant/ansible-role-nginx

And use it as described in its README.md

Upvotes: 1

Related Questions