# Looking for a way execute tasks in included file based on condition

**URL:** <https://forum.ansible.com/t/looking-for-a-way-execute-tasks-in-included-file-based-on-condition/19172>\
**Category:** Ansible Project\
**Created:** [September 2, 2015, 6:38pm UTC](https://forum.ansible.com/t/looking-for-a-way-execute-tasks-in-included-file-based-on-condition/19172 "2015-09-02T18:38:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_DJOMEDA](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Joseph\_DJOMEDA](https://forum.ansible.com/u/Joseph_DJOMEDA)\
**Post date:** [September 2, 2015, 6:38pm UTC](https://forum.ansible.com/t/looking-for-a-way-execute-tasks-in-included-file-based-on-condition/19172/1 "2015-09-02T18:38:19Z")

</div>

Hello Guys,

This has been probably solved before so apologies if this is a repeat. I was confused about tasks in a include file being run even though the condition for the include itself is not true.

so in my main.yml I have an include system like a switch kind of logique: say

- include: this.yml

when: include\_this\_enable|default(false)

- include: that.yml

when: include\_that\_enable|default(false)

To my surprise I needed to also add the when conditions to this.yml and that.yml for it to work before everything would run otherwise as shown in here [http://pastie.org/10392488](http://pastie.org/10392488)

when this.yml has a lot of tasks this become difficult to do. How to strictly run tasks in this.yml only base on a condition?

Thanks in advance

Best Regads,

---

<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 2, 2015, 8:42pm UTC](https://forum.ansible.com/t/looking-for-a-way-execute-tasks-in-included-file-based-on-condition/19172/2 "2015-09-02T20:42:30Z")

</div>

The when conditions will not avoid issues with a undefined or  
incorrectly typed var in a with\_ , as they get executed for each item  
inside the with\_.

---

<div class="post-metadata">

**Author:** ![Joseph\_DJOMEDA](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@Joseph\_DJOMEDA](https://forum.ansible.com/u/Joseph_DJOMEDA)\
**Post date:** [September 2, 2015, 9:15pm UTC](https://forum.ansible.com/t/looking-for-a-way-execute-tasks-in-included-file-based-on-condition/19172/3 "2015-09-02T21:15:38Z")

</div>

Hello Brian,

Thanks for the email. So there is no way to skip the inclusion of the file in the first place?

Best Regards,
