# Specifying automatically installable collection dependencies

**URL:** <https://forum.ansible.com/t/specifying-automatically-installable-collection-dependencies/2834>\
**Category:** Get Help\
**Tags:** role, playbook, collections\
**Created:** [December 10, 2023, 12:40pm UTC](https://forum.ansible.com/t/specifying-automatically-installable-collection-dependencies/2834 "2023-12-10T12:40:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmpod](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tmpod/32/1758_2.png) [@tmpod](https://forum.ansible.com/u/tmpod)\
**Post date:** [December 10, 2023, 12:40pm UTC](https://forum.ansible.com/t/specifying-automatically-installable-collection-dependencies/2834/1 "2023-12-10T12:40:55Z")

</div>

Hello!

I’m giving ansible a try to automate provisioning of some different VMs, and I found this good article: [https://www.redhat.com/sysadmin/build-VM-fast-ansible](https://www.redhat.com/sysadmin/build-VM-fast-ansible)  
Now, I wanted to specify the libvirt dependency in the role itself, to avoid having to remember to run the install command. I looked at the docs and found that `meta/requirements.yml` is the place to define role and collection dependencies, however, when I tried it, the dependencies were not automatically installed. If I specified them in the `meta/main.yml` file, it tried to install, but failed since there you can only specify roles, not collections (as far as I understand).  
Am I doing something wrong? How can I do this?

Thank you!

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [December 10, 2023, 1:06pm UTC](https://forum.ansible.com/t/specifying-automatically-installable-collection-dependencies/2834/2 "2023-12-10T13:06:33Z")

</div>

I don’t hink this is possible, and it looks like this isn’t planned to be implemented either: [Ansible role dependency handling for collections](https://github.com/ansible/ansible/issues/76030).

You could use [community.general.ansible\_galaxy\_install](https://docs.ansible.com/ansible/latest/collections/community/general/ansible_galaxy_install_module.html) to install the required collections in you role. But then you would rely on `community.general` being installed and can’t define this as a dependency… which means you’re more or less where you are now.

Sorry, I don’t have an idea how to achieve this. But maybe I’m wrong and someone else comes up with a solution.

---

<div class="post-metadata">

**Author:** ![tmpod](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tmpod/32/1758_2.png) [@tmpod](https://forum.ansible.com/u/tmpod)\
**Post date:** [December 10, 2023, 7:03pm UTC](https://forum.ansible.com/t/specifying-automatically-installable-collection-dependencies/2834/3 "2023-12-10T19:03:44Z")

</div>

Well, that’s quite unfortunate… It would be quite handy to be able to specify dependencies for the role and have it neatly ensure they’re all satisfied before executing the actual tasks.

Your suggestion of using the ansible\_galaxy\_installer is not that bad, it’s more likely people have community.general installed than whatever the other myriad of dependencies the role may have.

Thank you for your response!

* * *

PS: Should I mark your reply as the solution? It’s not really a solution, but seeing as the problem doesn’t seem to have one, and you gave a pretty good suggestion, I think it’s fitting. Want to make sure, though!

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [December 10, 2023, 7:39pm UTC](https://forum.ansible.com/t/specifying-automatically-installable-collection-dependencies/2834/4 "2023-12-10T19:39:21Z")

</div>

Hi,

I also think think this is not possible ATM. To add to @mariolenz comment, you could either use [ansible.builtin.git](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html) module to clone / pull [community.libvirt repository](https://github.com/ansible-collections/community.libvirt) (and other dependencies you might have), or [ansible.builtin.pip](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/pip_module.html) to specifically target a requirements file and install your dependencies. Just add either a `pre_tasks` in your playbook or a dedicated task in your role. This is not very elegant, but it should do the trick.

Also ensure you defined your roles / collections paths in your Ansible config (be it from envvar or ansible.cfg) to match destination path you chose using git / pip modules.

> PS: Should I mark your reply as the solution? It’s not really a solution, but seeing as the problem doesn’t seem to have one, and you gave a pretty good suggestion, I think it’s fitting. Want to make sure, though!

Yeah, I think that’s the best answer you’ll get. I would have suggested the same TBH.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 9, 2024, 7:39pm UTC](https://forum.ansible.com/t/specifying-automatically-installable-collection-dependencies/2834/5 "2024-01-09T19:39:24Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
