# multiple playbooks or one playbook per function?

**URL:** <https://forum.ansible.com/t/multiple-playbooks-or-one-playbook-per-function/31679>\
**Category:** Ansible Project\
**Created:** [November 18, 2019, 9:57pm UTC](https://forum.ansible.com/t/multiple-playbooks-or-one-playbook-per-function/31679 "2019-11-18T21:57:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio\_Tavares](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mauricio\_Tavares](https://forum.ansible.com/u/Mauricio_Tavares)\
**Post date:** [November 18, 2019, 9:57pm UTC](https://forum.ansible.com/t/multiple-playbooks-or-one-playbook-per-function/31679/1 "2019-11-18T21:57:20Z")

</div>

By playbook per function I mean something like a web.yml  
playbook which defines how all the webservers are put together. Of  
course we could then define variables associated with host groups and  
hosts themselves to take care of the local idiosyncrasies that make  
them unique (location, fw rules it it has more than one IP, which repo  
it should be sucking data from, etc).

Now what about network thingies such as routers, switches, traffic  
monitoring appliances, and whatnots? Should they all be inside, say,  
network.yml and then do the same as above? Maybe even having different

- hosts:  
&nbsp;&nbsp;&nbsp;&nbsp;- switches  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;roles:

- hosts:  
&nbsp;&nbsp;&nbsp;&nbsp;- scan  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;roles:

- hosts:  
&nbsp;&nbsp;&nbsp;&nbsp;- routers  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;roles:

within the same playbook. After all I can run ansible specifying I  
want this playbook to be only applied to that host or group of hosts.  
Or just have one playbook for each of these groups. I see pros and  
cons on each of them but am curious about what is The Proper Way \<tm\>.

Thoughts?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [November 19, 2019, 1:29am UTC](https://forum.ansible.com/t/multiple-playbooks-or-one-playbook-per-function/31679/2 "2019-11-19T01:29:51Z")

</div>

Such flexibility is available at the project level provided by  
ansible-runner. Take a look at "Runner Input Directory Hierarchy"  
[https://ansible-runner.readthedocs.io/en/latest/intro.html#inputdir](https://ansible-runner.readthedocs.io/en/latest/intro.html#inputdir)

Keep the roles and playbooks modular and as simple as possible. This will  
make both security screening and maintenance easier. Put the elements (roles,  
playbooks, inventory, ...) together by linking the directories and files into  
a projects.

To deliver and integrate, such projects can be encapsulated in Python. See  
"Using Runner as a Python Module Interface to Ansible"  
[https://ansible-runner.readthedocs.io/en/latest/python\_interface.html](https://ansible-runner.readthedocs.io/en/latest/python_interface.html)

Cheers.

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 19, 2019, 8:46pm UTC](https://forum.ansible.com/t/multiple-playbooks-or-one-playbook-per-function/31679/3 "2019-11-19T20:46:43Z")

</div>

I don’t think there’s a proper way, ultimately its whatever works for you.  
I do actually have 1 playbook per cluster type, but I have quite ‘tall’ software stacks (lots of steps to configure each cluster) and then I use external tools such as jenkins or gnu parallels to run multiple playbooks simultaneously (which I can do as typically I don’t ‘double-up’ and have hosts function as more than one type of cluster member).

I think I probably wouldn’t do that if I had simpler clusters which didn’t need so many tasks applied to them to ensure they are properly configured.  
If you often need to build all your cluster types at once then maybe having multiple playbooks would work for you.  
I’d definitely recommend pushing down any complexity into roles (and even into multiple tasks files within roles) as this lets you re-use roles in your playbooks.  
Hope this helps,  
Jon
