3

I've specified dependency for my role by declaring it inside meta/main.yml.

---
dependencies:
  - role: angstwad.docker_ubuntu
    src: https://github.com/angstwad/docker.ubuntu
    scm: git
    version: v2.3.0

However when I try to execute Ansible playbook I'm seeing error message:

ERROR! the role 'angstwad.docker_ubuntu' was not found in /home/.../ansible/roles:/etc/ansible/roles:/home/.../ansible/roles:/home/.../ansible

The error appears to have been in '/home/.../roles/docker-node/meta/main.yml': line 5, column 5, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  - role: angstwad.docker_ubuntu
    ^ here

From the error message I conclude that external role angstwad.docker_ubuntu hasn't be imported, even if it has been explicitly mentioned in docker-node/meta/main.yml.


Can I specify external dependencies from Ansible Galaxy even if my role itself has not been uploaded to Ansible Galaxy?

Or do I need to explicitly import them using ansible-galaxy?


From Ansible documentation:

Roles can also be dependent on other roles, and when you install a role that has dependencies, those dependenices will automatically be installed.

You specify role dependencies in the meta/main.yml file by providing a list of roles. If the source of a role is Galaxy, you can simply specify the role in the format username.role_name. The more complex format used in requirements.yml is also supported, allowing you to provide src, scm, version and name.

By following suggestions from another SO question (How to automatically install Ansible Galaxy roles?) it sounds like downloading external dependencies needs to be done explicitly either manually or with workaround.

Community
  • 1
  • 1
luka5z
  • 7,525
  • 6
  • 29
  • 52
  • 1
    What is the exact error message? – Konstantin Suvorov Mar 29 '17 at 13:07
  • Are you sure the error message does not start with `ERROR! the role 'angstwad.docker_ubuntu' was not found in`? Basically it seems to me as if you had already answered your own question. – techraf Mar 29 '17 at 14:03
  • @techraf Yes Ansible is unable to locate an external role, even though I've specified it in `meta/main.yml`. But shouldn't it try to download it based on given specifiers? This isn't clear to me. – luka5z Mar 29 '17 at 21:19
  • If "*yes*" -- it means you still have not included the error message. "*when you install a role*" -- did you install the role? – techraf Mar 29 '17 at 21:49

2 Answers2

2

If the role that has this dependency is itself being installed via ansible-galaxy, then revise meta/main.yml to look like this:

---
dependencies:
  - src: https://github.com/angstwad/docker.ubuntu.git
    scm: git
    version: v2.3.0

Thus, when installing the primary role the docker.ubuntu role will automatically be installed in ~/.ansible/roles/docker.ubuntu and it will run when the playbook is executed.

If the role that has this dependency will NOT be installed via ansible-galaxy, that is, if the dependency is the only thing being installed via the ansible-galaxy command, then docker.ubuntu will have to be installed separately, e.g.

ansible-galaxy install git+https://github.com/angstwad/docker.ubuntu.git

or

ansible-galaxy install git+https://github.com/angstwad/docker.ubuntu.git -p /path_to/my_playbook/roles

This will place the role in your search path (again, ~/.ansible/roles/docker.ubuntu if not specified via -p). In this scenario, revise meta/main.yml to this:

---
dependencies:
  - role: docker.ubuntu

Note that when pulling your role from github, it lands as docker.ubuntu vs docker_ubuntu. See https://galaxy.ansible.com/docs/using/installing.html#dependencies for more. Hope this helps.

0

As per documentation you linked, you see:

When dependencies are encountered by ansible-galaxy, it will automatically install each dependency to the roles_path.

Downloading of dependencies is handled by ansible-galaxy only, the src meta information doesn't affect ansible-playbook, which just looks inside your role directory and if it don't see a corresponding folder - it fails. As in answer in question you linked, you can indeed create a first task, or include in you playbook to run ansible galaxy before each start.

Community
  • 1
  • 1
Andrew
  • 3,912
  • 17
  • 28
  • 1
    I wonder what is the use of `src` in `meta/main.yml` file? Is there any? I find it very misleading. – luka5z Mar 30 '17 at 11:30