1

When I run the following ansible command:

$ ansible-playbook deploy/solo/wifi.yml -i inventories/solo

I got the following error message:

ERROR! the role 'solo/controller/wifi' was not found in /home/peng/git/uavops/deploy/roles:/home/peng/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/peng/git/uavops/deploy

The error appears to be in '/home/peng/git/uavops/deploy/wifi.yml': line 5, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  roles:
    - solo/controller/wifi
      ^ here

How did this happen? I invoke the ansible-playbook under the working directory /home/peng/git/uavops. Yet ansible-playbook ignores it and try to find the roles in directory /home/peng/git/uavops/deploy.

How do I tell ansible to locate the right role directory?

tribbloid
  • 4,026
  • 14
  • 64
  • 103

1 Answers1

1

By default, Ansible looks for roles in two locations:

 roles/ #   in a directory called relative to the playbook file

/etc/ansible/roles

If you store your roles in a different location, set the roles_path configuration option so Ansible can find your roles. Checking shared roles into a single location makes them easier to use in multiple playbooks. See Configuring Ansible for details about managing settings in ansible.cfg.

Alternatively, you can call a role with a fully qualified path:

---
- hosts: webservers
  roles:
    - role: '/path/to/my/roles/common'

You can set role_path in your inventory file to tell ansible where to search role.

In your case,

  1. you should move your roles inside a directory called roles at same level as the playbook.

  2. Full path of the role or

    roles: - home/peng/git/uavops/deploy/solo/controller/wifi

  3. use role_path to point to desired location.

P....
  • 17,421
  • 2
  • 32
  • 52
  • So it has nothing to do with the working directory ... Sounds really difficult to organize – tribbloid Aug 01 '21 at 19:31
  • 1
    I typically keep all the roles in one directory and keep softlink to that directory in all the playbook directory. This keep things very simple and organized – P.... Aug 01 '21 at 19:34