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
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?
You could use community.general.ansible_galaxy_install 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.
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!
I also think think this is not possible ATM. To add to @mariolenz comment, you could either use ansible.builtin.git module to clone / pull community.libvirt repository (and other dependencies you might have), or ansible.builtin.pip 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.