# Role Includes When Statement

**URL:** <https://forum.ansible.com/t/role-includes-when-statement/22874>\
**Category:** Ansible Developer\
**Created:** [October 25, 2016, 1:23am UTC](https://forum.ansible.com/t/role-includes-when-statement/22874 "2016-10-25T01:23:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve5](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@steve5](https://forum.ansible.com/u/steve5)\
**Post date:** [October 25, 2016, 1:23am UTC](https://forum.ansible.com/t/role-includes-when-statement/22874/1 "2016-10-25T01:23:43Z")

</div>

I am on the most recent version of the devel branch, and I have a role dependency in the meta of that role, and when I set it I have a when statement. Now it skips everything when it runs except a task with\_items, and it fails b/c the object is defined, which makes sense because everything else was skipped so the with\_items was not defined in the previous steps. I tried to put a when statement on that with\_items step but it doesn’t seem to prevent it from running and it gives me a failure.

`

---

<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:** [October 25, 2016, 2:22am UTC](https://forum.ansible.com/t/role-includes-when-statement/22874/2 "2016-10-25T02:22:12Z")

</div>

when: runs INSIDE the with\_items loops, so it cannot prevent definition errors, use |default() as an empty list will skip the loop.

[http://docs.ansible.com/ansible/playbooks\_conditionals.html#loops-and-conditionals](http://docs.ansible.com/ansible/playbooks_conditionals.html#loops-and-conditionals)
