# only\_if with task includes ?

**URL:** <https://forum.ansible.com/t/only-if-with-task-includes/11699>\
**Category:** Ansible Project\
**Created:** [July 18, 2012, 3:03pm UTC](https://forum.ansible.com/t/only-if-with-task-includes/11699 "2012-07-18T15:03:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [July 18, 2012, 3:03pm UTC](https://forum.ansible.com/t/only-if-with-task-includes/11699/1 "2012-07-18T15:03:12Z")

</div>

Is there a plan to have 'only\_if' at includes within tasks ?

I am passing the --extra-vars="product=theproduct" to the playbook. So  
it makes it resuable for each product.  
My tasks i have broken up completely into multiple incudes, which do  
read the product specific tasks - which works great now btw. !

tasks:  
...  
- include: tasks/${product}.yml  
...

There is a product i might like to skip one or more of theses include  
statements:  
Choices to achieve that would be:

- Give no tasks/theproduct.yml file.  
&nbsp;&nbsp;=\> brings directly a parser error: ERROR: file not found: tasks/  
theproduct.yml

- place an empty file tasks/theproduct.yml  
&nbsp;&nbsp;=\> you get this error:  
&nbsp;&nbsp;Traceback (most recent call last):  
&nbsp;&nbsp;File "/usr/bin/ansible-playbook", line 108, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;sys.exit(main(sys.argv[1:]))  
&nbsp;&nbsp;File "/usr/bin/ansible-playbook", line 89, in main  
&nbsp;&nbsp;&nbsp;&nbsp;pb.run()  
&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/ansible/playbook/  
\_\_init\_\_.py", line 152, in run  
&nbsp;&nbsp;&nbsp;&nbsp;self.\_run\_play(Play(self,play\_ds))  
&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/ansible/playbook/play.py",  
line 81, in \_\_init\_\_  
&nbsp;&nbsp;&nbsp;&nbsp;self.\_tasks = self.\_load\_tasks(self.\_ds, 'tasks')  
&nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/ansible/playbook/play.py",  
line 115, in \_load\_tasks  
&nbsp;&nbsp;&nbsp;&nbsp;for y in data:  
&nbsp;&nbsp;TypeError: 'NoneType' object is not iterable

- Use tags=theproduct  
&nbsp;&nbsp;That would need to be the negative way to directly exclude the  
'include' statement.  
&nbsp;&nbsp;Otherwise everything else would need to be tagged positively which  
isnt possible afaik.

- Have an 'only\_if' attached to the include statement in tasks.

- Have a separate playbook - which is not the goal...

- Place a tasks/theproduct.yml file with action: echo foo (that  
works btw.)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 18, 2012, 3:12pm UTC](https://forum.ansible.com/t/only-if-with-task-includes/11699/2 "2012-07-18T15:12:58Z")

</div>

Conditional includes would be host specific, and tasks are the same for all hosts in the play, so no.
