# How do you avoid running same roles multiple times when including playbooks?

**URL:** <https://forum.ansible.com/t/how-do-you-avoid-running-same-roles-multiple-times-when-including-playbooks/22330>\
**Category:** Ansible Project\
**Created:** [August 19, 2016, 9:25pm UTC](https://forum.ansible.com/t/how-do-you-avoid-running-same-roles-multiple-times-when-including-playbooks/22330 "2016-08-19T21:25:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacek.sniecikowski](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jacek.sniecikowski](https://forum.ansible.com/u/jacek.sniecikowski)\
**Post date:** [August 19, 2016, 9:25pm UTC](https://forum.ansible.com/t/how-do-you-avoid-running-same-roles-multiple-times-when-including-playbooks/22330/1 "2016-08-19T21:25:57Z")

</div>

Short version:  
Why does Ansible keep running ‘-include: mysql-cluster.yml’ whenever it encounters it? Can’t it recognize this was already executed once?

Long version:  
I am trying to find a good way to organize Ansible scripts so that they meet these requirements:

- Developers can run their project and not worry about running any dependencies manually
- Have a master playbook describing our whole infrastructure (site.yml) and not call dependencies multiple times even though they already run.

We’re running a mid size setup with site.yml that is a list of other playbooks that we include.  
`

# file: site.yml

# This is a top level playbook representing everything in Polaris.

# It includes subplaybooks for independent collections of modules that may be deployed together.

# Infrastructure

- include: cdh5.yml
- include: memcached.yml
- include: myAPI\_1.yml
- include: myAPI\_2.yml

( and so on )

`

The myAPI\_1 and myAPI\_2 playbook look like this:

`

file: myAPI\_1.yml

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [August 20, 2016, 10:28am UTC](https://forum.ansible.com/t/how-do-you-avoid-running-same-roles-multiple-times-when-including-playbooks/22330/2 "2016-08-20T10:28:39Z")

</div>

Use a when: clause, or make the included files tasks idempotent.

---

<div class="post-metadata">

**Author:** ![Jacek\_Sniecikowski](https://avatars.discourse-cdn.com/v4/letter/j/ce73a5/32.png) [@Jacek\_Sniecikowski](https://forum.ansible.com/u/Jacek_Sniecikowski)\
**Post date:** [August 22, 2016, 5:03pm UTC](https://forum.ansible.com/t/how-do-you-avoid-running-same-roles-multiple-times-when-including-playbooks/22330/3 "2016-08-22T17:03:41Z")

</div>

So basically I will need to set facts for every major playbook once it succeeds and then check for it?  
I thought Ansible was idempotent in this way by default
