<p>What I have done before goes on the same direction as Zeitounator commented; you can have one or more &quot;meta&quot; or master playbooks that import the ones you need to run your entire automation. To add to Zaito's comment; you can use the <code>when</code> clause on <code>import_playbook</code> or <code>include</code> to control the execution of those &quot;inner&quot; playbooks; something like this:</p>
<p>Say you want to execute PlatformB playbooks only for an stg or prod environment using a defined <code>env</code> ansible variable:</p>
<pre><code>- include: platformA/do_something_on_platformA.yml
- include: platformB/do_something_on_platformB.yml
  when: env == 'stg' or env == 'prod'
</code></pre>
<p>you could change the value of <code>env</code> using <code>--extra-vars</code> on execution time or something.</p>
<p>hope it helps, cheers.</p>

CC BY-SA 4.0
2020-06-17T21:05:08.947Z
2020-06-18T12:07:48.533Z
2020-06-18T12:07:48.533Z
Pablo Arango
<p>Say, i have written bunch of ansible roles and playbooks, configured  my playbooks structure and now i'm trying to tie them to one playbook which will do its thing depending on tags or inventory file provided. Should i strive for that? Or is it better to have bunch of playbooks and call them depending on the tasks/hosts needed? What is the best way to go about this? I can't seem to find any example of tying it all together in one playbook or bunch of them which will do its thing to ones infrastructure depending on arguments provided. </p>

<p>Best practice in ansible docs covers organization of playbook structure but not organization of playbook use on infrastructure. Is there any examples of organizing playbooks use on infrastructure?</p>

CC BY-SA 4.0
2020-06-17T09:55:06.370Z
Did you consider creating a "meta" playbook (or several) using [`import_playbook`](https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html) ? I did this recently for a client to organize several playbooks to take in charge different parts of a WebSphere cluster install and application deployment. Each playbook can be run independently or your can run a meta one that will orchestrate all of them. Does this somewhat answer your question ?
Zeitounator
<ansible><infrastructure-as-code>
Tying playbooks together
bob-the-builder
# Tying playbooks together

(Asked by: username_0 on 2020-06-17)

Say, i have written bunch of ansible roles and playbooks, configured my playbooks structure and now i'm trying to tie them to one playbook which will do its thing depending on tags or inventory file provided. Should i strive for that? Or is it better to have bunch of playbooks and call them depending on the tasks/hosts needed? What is the best way to go about this? I can't seem to find any example of tying it all together in one playbook or bunch of them which will do its thing to ones infrastructure depending on arguments provided.

Best practice in ansible docs covers organization of playbook structure but not organization of playbook use on infrastructure. Is there any examples of organizing playbooks use on infrastructure?

**Tags:** ansible, infrastructure-as-code

> **Comments:**
> **username_1**: Did you consider creating a "meta" playbook (or several) using [`import_playbook`](https://docs.ansible.com/ansible/latest/modules/import_playbook_module.html) ? I did this recently for a client to organize several playbooks to take in charge different parts of a WebSphere cluster install and application deployment. Each playbook can be run independently or your can run a meta one that will orchestrate all of them. Does this somewhat answer your question ?  

---

## 1 answers

### Answer by username_2 on 2020-06-17. Score: 1

What I have done before goes on the same direction as username_1 commented; you can have one or more "meta" or master playbooks that import the ones you need to run your entire automation. To add to Zaito's comment; you can use the when clause on import_playbook or include to control the execution of those "inner" playbooks; something like this:
Say you want to execute PlatformB playbooks only for an stg or prod environment using a defined env ansible variable:
- include: platformA/do_something_on_platformA.yml
- include: platformB/do_something_on_platformB.yml
  when: env == 'stg' or env == 'prod'

you could change the value of env using --extra-vars on execution time or something.
hope it helps, cheers.


---

