skip to Main Content

i am running an ansible playbook, but it won’t find my defined roles. I get the following error:

ERROR! the role 'Users/xxxx/ansible/roles/basic_install' was not found in /Users/xxxx/ansible/playbooks/roles:/Users/xxxx/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/Users/xxxx/ansible/playbooks

The error appears to be in '/Users/xxxx/ansible/playbooks/byrule.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: 'Users/xxxx/ansible/roles/basic_install'
      ^ here

I have the following ansible structure:


ansible/
  ansible.cfg
  inventory
  playbooks/
    byrule.yml
  rules/
    basic_install/
      tasks/
        main.yml
    full_install/
      tasks/
        main.yml

Content of the used playbook:

---
- name: Basic install of packages on Debian
  hosts: all
  become: true
  roles:
    - basic_install

- name: Full install of packages on Debian
  hosts: all
  become: true
  roles:
    - full_install

Best Regards

Based on the error output, i tried to give the rule as a path in the playbook, or move the rules directory into the playbooks directory, but none of them worked, i still get the same error. I would be very grateful for any help.

2

Answers


  1. Chosen as BEST ANSWER

    If you ever anticipate this error, the problem is that the playbooks are inside the playbooks directory, and by default ansible looks there for the roles. The correct way is to keep the playbooks at the same level as the roles directory.


  2. As described in the ansible documentations

    By default, Ansible looks for roles in the following locations:

    • in collections, if you are using them
    • in a directory called roles/, relative to the playbook file
    • in the configured roles_path. The default search path is ~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles.
    • in the directory where the playbook file is located

    when running the playbook you need to make sure not to be in the playbooks directory but in the main dir of the project – in your case the ansible dir

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search