# Conditional role "include\_role:" doesn't work (with "when:"), neither with "with\_items".

**URL:** <https://forum.ansible.com/t/conditional-role-include-role-doesnt-work-with-when-neither-with-with-items/23070>\
**Category:** Ansible Project\
**Created:** [November 22, 2016, 6:02am UTC](https://forum.ansible.com/t/conditional-role-include-role-doesnt-work-with-when-neither-with-with-items/23070 "2016-11-22T06:02:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Martins](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Thiago\_Martins](https://forum.ansible.com/u/Thiago_Martins)\
**Post date:** [November 22, 2016, 6:02am UTC](https://forum.ansible.com/t/conditional-role-include-role-doesnt-work-with-when-neither-with-with-items/23070/1 "2016-11-22T06:02:28Z")

</div>

Guys,

I’m trying to create a top-level playbook, based on “include\_role:”, instead of “roles:”, however, the “when:” condition isn’t working properly, I think.

Easy to reproduce (the content of “roles/hello-world-X/tasks/main.yml” is in the end):

This works (“include\_role:” without the “when:” condition):

$ ansible --version  
ansible 2.2.0.0

$ source ~/my-openstack-project-openrc.sh

$ ansible-playbook -i openstack.py hello.yml

---

<div class="post-metadata">

**Author:** ![Lorrin\_Nelson1](https://avatars.discourse-cdn.com/v4/letter/l/6bbea6/32.png) [@Lorrin\_Nelson1](https://forum.ansible.com/u/Lorrin_Nelson1)\
**Post date:** [November 25, 2016, 9:08pm UTC](https://forum.ansible.com/t/conditional-role-include-role-doesnt-work-with-when-neither-with-with-items/23070/2 "2016-11-25T21:08:17Z")

</div>

I am also seeing when: not work with include\_role. The “a” reported above is just the first letter of Thiago’s condition (ansible\_hostname | search(“stack-1-sql.\*”). I’ve got a boolean, etcd\_enabled, so my when: etcd\_enabled produces “The conditional check ‘e’ failed”

---

<div class="post-metadata">

**Author:** ![Mario\_Wolff](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Mario\_Wolff](https://forum.ansible.com/u/Mario_Wolff)\
**Post date:** [January 12, 2017, 7:57am UTC](https://forum.ansible.com/t/conditional-role-include-role-doesnt-work-with-when-neither-with-with-items/23070/3 "2017-01-12T07:57:15Z")

</div>

Is there something new on this topic?

I’m using some Galaxy roles and i would like to avoid any modification. Some of these roles do much more than i need and i would like to do something like:

- name: selective tasks from galaxy role  
include\_role:  
name: someones.role  
tasks\_from: “{{ item }}”  
static: no  
with\_items:
- prereq.yml
- installa.yml
- starta.yml
- testa.yml

Where the role has also install[b-d].yml included from the main.yml

Here i get the already known

ERROR! Could not find specified file in role: {{ item }}

Regards,  
Mario

BTW: $ ansible --version  
ansible 2.2.0.0

---

<div class="post-metadata">

**Author:** ![Hany\_Fahim](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@Hany\_Fahim](https://forum.ansible.com/u/Hany_Fahim)\
**Post date:** [March 18, 2017, 7:54pm UTC](https://forum.ansible.com/t/conditional-role-include-role-doesnt-work-with-when-neither-with-with-items/23070/4 "2017-03-18T19:54:15Z")

</div>

I’m getting the exact same issue. When using “when” with “include\_role”, I get:

The conditional check ‘g’ failed. The error was: error while evaluating conditional (g): ‘g’ is undefined
