Referencing paths inside roles

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, if you rearrange files paths have to change. That doesn't seem
to be terrible though.

Keeping things at the same level and following a common structure
avoids surprises.

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?

http://ansible.cc/docs/bestpractices.html

https://github.com/ansible/ansible-examples

This last repo is just a start, we have a lot more full-stack (or
should I say, more full use case) examples coming.

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:

  • hosts: webservers
    include:
  • …/roles/common/main.yml
  • …/roles/php-fpm/main.yml

and roles/php-fpm/main.yml:

  • tasks:
  • name: php-fpm config
    action: template src=‘templates/www.conf.j2’ dest=‘/etc/php5/fpm/pool.d/www.conf’

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.

All your parent playbooks should be at the same directory level.

Including plays inside of other plays doesn't make sense.

Playbook includes as they stand today:

- include: play1.yml
- include: play2.yml

produce a list of plays.

We obviously also have task includes.

You really should keep your master playbooks at the same level.

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:

  • include: …/roles/common/common.yml
    vars:
    hosts: webservers
  • include: …/roles/php-fpm/main.yml
    vars:
    hosts: webservers

and then inside each role:

  • hosts: $hosts
    tasks:

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.

You can include another playbooks inside a playbook, but child playbooks
need to have set at least hosts param.

Misconception here. You can't include playbooks inside playbooks,
because it doesn't make sense at all. Playbooks are a list of plays,
and when you do

- include: blarg
- play goes here in full
- include: blarg

What you are doing is making a linear list of 3 plays.

Playbooks do not nest. Nor do task includes. It's always two levels
deep -- plays then tasks.

ok, I was using terminology from your website:
“Playbooks Including Playbooks
To further advance the concept of include files, playbook files can include other playbook files.”
http://ansible.cc/docs/playbooks2.html#playbooks-including-playbooks

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.

If you wish to have something similar to merging plays together, you
should look into task includes.