breaking up complex playbook into pieces

105 views
Skip to first unread message

Dmitry Makovey

unread,
Jun 25, 2014, 1:02:39 PM6/25/14
to ansible...@googlegroups.com
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?

Michael DeHaan

unread,
Jun 25, 2014, 8:12:43 PM6/25/14
to ansible...@googlegroups.com
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.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fd5dab1a-0745-4a17-a109-96f49276a0a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dmitry Makovey

unread,
Jun 26, 2014, 6:10:31 PM6/26/14
to ansible...@googlegroups.com


On Wednesday, June 25, 2014 6:12:43 PM UTC-6, Michael DeHaan wrote:
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 ?  

Michael DeHaan

unread,
Jun 27, 2014, 8:45:27 AM6/27/14
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages