I'm having trouble to figure out how to delegate the installation of a subproject with Ansible.
Here is my situation
I maintain 2 projects, one of them is used by the other. Let's call them:
- Project_parent
- Project_child
I already wrote an installation playbook for Project_child, which now lives in the git repository.
Project_child/deploy/
- site.yml
- roles/
- role_A
- role_B
- role_C
My goal is to write a playbook for the Project_parent, and delegate the Project_child's installation to the child's itself (since I already wrote the playbook)
Solution 1 - import_playbook
Write Project_parent's playbook, and import the child's playbook to delegate the installation.
Problem: you can only call import_playbook from the top-level, so this doesn't work:
Project_parent/deploy
- site.yml
- roles/
- Project_child/tasks/main.yml -> git clone && import_playbook here # doesnt' work
So this doesn't work.
Solution 2 - Ansible collections
The idea is to package Project_child's roles into a collection, and reuse it in Project_parent.
Project_parent/deploy
- site.yml
- roles/
- namespace.collection.role_A
- namespace.collection.role_B
- namespace.collection.role_C
- roleD
- roleE
...
--> The issue I have with this approach is that we have tighly coupled the parent's playbook with the child's role set.
If the child's role set changes (add, remove, rename), the parent playbook must be updated as well.
So this isn't the "installation delegation" I would expect.
I would like an equivalent of "make -C Project_child" for Ansible.
Is there anything I am missing to achieve this ?
Thanks !