# Trouble with using an include based on conditional

**URL:** <https://forum.ansible.com/t/trouble-with-using-an-include-based-on-conditional/23615>\
**Category:** Ansible Project\
**Created:** [February 1, 2017, 9:50pm UTC](https://forum.ansible.com/t/trouble-with-using-an-include-based-on-conditional/23615 "2017-02-01T21:50:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alicia\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Alicia\_Smith](https://forum.ansible.com/u/Alicia_Smith)\
**Post date:** [February 1, 2017, 9:50pm UTC](https://forum.ansible.com/t/trouble-with-using-an-include-based-on-conditional/23615/1 "2017-02-01T21:50:12Z")

</div>

This is being copied from the bug that just got closed:

##### ANSIBLE VERSION

```auto
ansible 2.2.1.0
 

```

##### CONFIGURATION

Nothing weird here

##### OS / ENVIRONMENT

MAC Sierra 10.12.3  
Destination: CentOS 7

##### SUMMARY

Using a conditional with the include for a task include is ignored.  
I have run it using static: no and without - the results are the same.

I am running this play for a web server which is defined as modef-prod-web.  
There are alert servers which run as mozdef-prod-alert.

Running this for mozdef-prod-web should essentially only include the mozdef-web.yml - and no other includes. But it doesn’t seem to check the conditional.

##### Inventory List

Inventory list:  
[mozdef-prod-web]  
192.168.250.134

[mozdef-prod-alert]

192.168.250.135

mozdef-update.yml:

- hosts: mozdef-prod-web  
remote\_user: phrozyn  
become: yes  
become\_user: someuser  
roles:
  - mozdef-update

```auto
- include: mozdef-alert.yml
  static: no
  when: ("'mozdef-prod-alert' in group_names") or ("'mozdef-dev' in group_names") or ("'mozdef-gen2-qa' in group_names")

- include: mozdef-consumer.yml
  static: no
  when: ("'mozdef-prod-ingest' in group_names") or ("'mozdef-dev' in group_names") or ("'mozdef-gen2-qa' in group_names")

- include: mozdef-web.yml
  static: no
  when: ("'mozdef-prod-web' in group_names") or ("'mozdef-dev' in group_names") or ("'mozdef-gen2-qa' in group_names")

- include: mozdef-qa.yml
  static: no
  when: ("'mozdef-gen2-qa' in group_names") or ("'mozdef-dev' in group_names")

 

```

##### EXPECTED RESULTS

TASK [mozdef-update : include] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /Users/Phrozyn/Projects/mozdef-dev/QA/ansible-eis/roles/mozdef-update/tasks/main.yml:45  
included: /Users/Phrozyn/Projects/mozdef-dev/QA/ansible-eis/roles/mozdef-update/tasks/mozdef-web.yml for 192.168.250.134

##### ACTUAL RESULTS

TASK [mozdef-update : include] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /Users/Phrozyn/Projects/mozdef-dev/QA/ansible-eis/roles/mozdef-update/tasks/main.yml:45  
included: /Users/Phrozyn/Projects/mozdef-dev/QA/ansible-eis/roles/mozdef-update/tasks/mozdef-alert.yml for 192.168.250.134

It of course dies when it runs because the webserver’s group\_vars don’t include variables for the alert tasks.

So any help would be appreciated!

Keep in mind, this fails whether or not static: no is designated

---

<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:** [February 6, 2017, 2:50pm UTC](https://forum.ansible.com/t/trouble-with-using-an-include-based-on-conditional/23615/2 "2017-02-06T14:50:31Z")

</div>

Since you are not showing a play, I'm going to guess that you are  
doing play includes, which cannot be made dynamic. ONLY task includes  
can, as the docs state:  
[http://docs.ansible.com/ansible/include\_module.html](http://docs.ansible.com/ansible/include_module.html)
