Search code examples
ansibleansible-role

Ansible-playbook search for roles in the wrong directory! How to correct it?


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?


Solution

  • 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.