Ansible, role not found error
Asked Answered
D

4

16

I try to play following playbook against localhost to provision Vagrant machine

---
- hosts: all
  become: yes
  roles:
    - base
    - jenkins

I have cloned necessary roles from github and they resides in a relative path roles/{role name}

Executing following command: ansible-playbook -i "localhost," -c local playbook.yml outputs this error:

==> default: ERROR! the role 'geerlingguy.java' was not found in /home/vagrant/provisioning/roles:/home/vagrant/provisioning:/etc/ansible/roles:/home/vagrant/provisioning/roles
==> default:
==> default: The error appears to have been in '/home/vagrant/provisioning/roles/jenkins/meta/main.yml': line 3, column 5, but may
==> default: be elsewhere in the file depending on the exact syntax problem.
==> default:
==> default: The offending line appears to be:
==> default:
==> default: dependencies:
==> default:   - geerlingguy.java
==> default:     ^ here

I cloned the missing dependency from github, and tried to reside it in relative path of roles/java and roles/geerlingguy/java, but either didn't solve the problem, and error stays the same.

I want to keep all roles locally in the synced provisioning folder, without using ansible-galaxy runtime, to make the provisioning method as self contained as possible.

Here is the provision folder structure as it is now

.
├── playbook.yml
└── roles
    ├── base
    │   └── tasks
    │       └── main.yml
    ├── java
    │   ├── defaults
    │   │   └── main.yml
    │   ├── meta
    │   │   └── main.yml
    │   ├── README.md
    │   ├── tasks
    │   │   ├── main.yml
    │   │   ├── setup-Debian.yml
    │   │   ├── setup-FreeBSD.yml
    │   │   └── setup-RedHat.yml
    │   ├── templates
    │   │   └── java_home.sh.j2
    │   ├── tests
    │   │   └── test.yml
    │   └── vars
    │       ├── Debian.yml
    │       ├── Fedora.yml
    │       ├── FreeBSD.yml
    │       ├── RedHat.yml
    │       ├── Ubuntu-12.04.yml
    │       ├── Ubuntu-14.04.yml
    │       └── Ubuntu-16.04.yml
    └── jenkins
        ├── defaults
        │   └── main.yml
        ├── handlers
        │   └── main.yml
        ├── meta
        │   └── main.yml
        ├── README.md
        ├── tasks
        │   ├── main.yml
        │   ├── plugins.yml
        │   ├── settings.yml
        │   ├── setup-Debian.yml
        │   └── setup-RedHat.yml
        ├── templates
        │   └── basic-security.groovy
        ├── tests
        │   ├── requirements.yml
        │   ├── test-http-port.yml
        │   ├── test-jenkins-version.yml
        │   ├── test-plugins-with-pinning.yml
        │   ├── test-plugins.yml
        │   ├── test-prefix.yml
        │   └── test.yml
        └── vars
            ├── Debian.yml
            └── RedHat.yml
Depressor answered 5/10, 2016 at 12:12 Comment(0)
A
12

You should install or clone all required roles in the /roles folder (or in the system folder)

ansible-galaxy install -p ROLES_PATH geerlingguy.java

should fix this specific problem.

However, the best practice should be the use of a requirements.yml file where you require all the needed roles and then install them with ansible-galaxy directly in your playbook.

- name: run ansible galaxy
  local_action: command ansible-galaxy install -r requirements.yml --ignore-errors
Alternant answered 5/10, 2016 at 12:37 Comment(2)
I tried the first example and it didn't fix the problem. I got the error that requirements file is required, so I tried the command as it is in ansible-galaxy documentation: sudo ansible-galaxy install -p $ROLES_PATH -r requirements.txt, where the content of requirements.txt is geerlingguy.java. Following error is raised: requirements.txt was NOT installed successfully: the file ==> default: downloaded was not a tar.gzDepressor
As you can see this error is raised if the tar file is somehow malformed. I just executed the sudo ansible-galaxy install -p my-folder -r requirements.txt (with only geerlingguy.java as content) on my dev box without problems. Why sudo by the way?Alternant
E
2

Simple symbolic link works like a charm without any installations:

$ mkdir /home/USER/ansible && ln -s /home/USER/GIT/ansible-root/roles
Eucalyptol answered 29/12, 2020 at 20:2 Comment(0)
D
1

Here is the solution: the required path for the role is roles/geerlingguy.java/, not roles/geerlingguy/java/

Depressor answered 6/10, 2016 at 7:43 Comment(0)
G
0

Another solution: add an ansible.cfg at the root level with:

[defaults]
roles_path = ..
Gloze answered 11/5 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.