breaking up complex playbook into pieces

Hi,

I’ve got my playbook large enough now that whenever I want to execute only bits of it I either have to code-in lots of conditionals and “special” variables or do some other trickery. I’ve got things split out into roles, so that my main file site.yml looks like:

  • hosts: all
    roles:

  • role: commonAll

  • role: collect_facts

  • hosts: groupA
    roles:

  • role: common1

  • role: roleA

  • hosts: groupB
    roles:

  • role: common2

  • role: roleB

now I would like to break this into bunch of smaller files and be able to execute them per-role/per-group. Thing is sometimes I have the same host in multiple groups (and subsequently in several roles) and executing with just “–limit” hooks into groups/roles I don’t want to. So I created bunch of files like:

…common.yml…

  • hosts: all
    roles:
  • role: commonAll
  • role: collect_facts

…fileA.yml…

  • hosts: groupA

roles:

  • role: common1
  • role: roleA


…fileB.yml…

  • hosts: groupB

roles:

  • role: commonB
  • role: roleB

…groupB.yml…

  • include common.yml
  • include fileB.yml

and master site.yml to look like:

  • include common.yml
  • include fileA.yml
  • include fileB.yml

so that I can either launch site.yml or any of the groups separately: groupX.yml . Now from all of the above, I get ridiculous number of files at the top level. Trying to move fileX.yml into subdirectory services results in ansible inability to locate roles definitions.

Now the actual question: what are the best practices in cases like the one I’ve described? One thing I can think of is to restructure everything introducing one more directory layer, so instead of book/roles/foo I’ll get top/book/roles/foo and move all of the fileX.yml under top/ and have groupX and site.yml files at the very top level. Is that how others are addressing such problems?

having a site.yml that includes a webservers.yml and a dbservers.yml is in fact a reasonable thing to do if you want a quick shorthand to just run a part of your infrastructure through Ansible.

how do I get around the issue of roles being relative to playbook file and not CWD ?

I’m not sure why it’s an issue, but I’m having difficulty following.

Please also note roles_path is configurable in ansible.cfg if this is useful to you.