# How to conditionally include other playbooks?

**URL:** <https://forum.ansible.com/t/how-to-conditionally-include-other-playbooks/22608>\
**Category:** Ansible Project\
**Created:** [September 21, 2016, 9:39pm UTC](https://forum.ansible.com/t/how-to-conditionally-include-other-playbooks/22608 "2016-09-21T21:39:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tristan\_Muntsinger](https://avatars.discourse-cdn.com/v4/letter/t/2acd7d/32.png) [@Tristan\_Muntsinger](https://forum.ansible.com/u/Tristan_Muntsinger)\
**Post date:** [September 21, 2016, 9:39pm UTC](https://forum.ansible.com/t/how-to-conditionally-include-other-playbooks/22608/1 "2016-09-21T21:39:37Z")

</div>

I tried this and it isn’t working as expected:

test.yml

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 22, 2016, 12:07am UTC](https://forum.ansible.com/t/how-to-conditionally-include-other-playbooks/22608/2 "2016-09-22T00:07:41Z")

</div>

playbooks cannot be included conditionally.

---

<div class="post-metadata">

**Author:** ![Tristan\_Muntsinger](https://avatars.discourse-cdn.com/v4/letter/t/2acd7d/32.png) [@Tristan\_Muntsinger](https://forum.ansible.com/u/Tristan_Muntsinger)\
**Post date:** [September 22, 2016, 6:45am UTC](https://forum.ansible.com/t/how-to-conditionally-include-other-playbooks/22608/3 "2016-09-22T06:45:18Z")

</div>

Is there an alternative solution to get the behavior I’d like?

-Tristan

---

<div class="post-metadata">

**Author:** ![cupcake](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@cupcake](https://forum.ansible.com/u/cupcake)\
**Post date:** [September 23, 2016, 1:05pm UTC](https://forum.ansible.com/t/how-to-conditionally-include-other-playbooks/22608/4 "2016-09-23T13:05:23Z")

</div>

I’ve done includes for playbooks based on facts typically OS

- name: include OS specific tasks  
include: “{{ ansible\_os\_family|lower }}.yml”

if there was a specifc fact you could use such OS, RAM, CPU, write a custom module to make that fact. I guess at that point why not target machines based on inventory groups.

-tp

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [September 23, 2016, 2:13pm UTC](https://forum.ansible.com/t/how-to-conditionally-include-other-playbooks/22608/5 "2016-09-23T14:13:36Z")

</div>

That will work with task includes, not play includes.
