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?