The ansible best pracitces content currently is using "../"
I strongly dislike any notion of new syntax, and because your
playbooks might be run at different levels, some notion of a variable
named "$base" does not make much sense.
I think "../" is not terrible when needed and strongly preferably to
introduction of new syntax.
What do you mean by that?
If I understand correctly, in included files, paths to file/template sources, which don’t start with / or ~, are resolved relative to parent playbook; so with “…/” you have the same problem I’ve described above.
Yes, it doesn’t seem terrible until you have 100 playbooks in one top dir and you can’t organize them anymore, because all paths will break.
btw. where can I find those new best practices?
ok, I don’t really see “…/” as an improvement, it looks even worse, as beside hardcoded role path inside role, now you also have hardcoded parent “roles/” path, and you still depend on the location of the parent playbook.
Anyway, I have another idea, which also fixes this problem, and maybe some others.
How about including plays inside other play, e.g. playbooks/webservers.yml:
This way, roles are just plays which will be merged inside plays in top playbook. You don’t even need separate tasks/handlers directories. For data keys that are set in both plays, parent play can have precedence.
I know about current includes, but there are problems with them.
You can include tasks and handlers in a play and have the above mentioned problem.
You can include another playbooks inside a playbook, but child playbooks need to have set at least hosts param. Parent playbook can have only include and vars params.
Yes, you can do something like this:
→ parent_playbook:
It could work, but again, it’s redundant and ugly.
And then you later want to, for example, change sudo play param and you need to edit both child and parent playbooks.
Compare that with example from my previous post.
It doesn’t really make a difference if you can have only one play inside included playbook, the same problem still applies.
My suggestion was not to add more levels of plays, but to merge them, the end result is still two levels. Similar to what you have now, but more flexible.