# Support for gathering facts before evaluating conditional playbook includes?

**URL:** <https://forum.ansible.com/t/support-for-gathering-facts-before-evaluating-conditional-playbook-includes/22117>\
**Category:** Ansible Project\
**Created:** [July 25, 2016, 9:08pm UTC](https://forum.ansible.com/t/support-for-gathering-facts-before-evaluating-conditional-playbook-includes/22117 "2016-07-25T21:08:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Brezinski](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@Thomas\_Brezinski](https://forum.ansible.com/u/Thomas_Brezinski)\
**Post date:** [July 25, 2016, 9:08pm UTC](https://forum.ansible.com/t/support-for-gathering-facts-before-evaluating-conditional-playbook-includes/22117/1 "2016-07-25T21:08:11Z")

</div>

Hello,

I’ve been looking at using the support for conditionally including playbooks, that was introduced in Ansible 2.0, to simplify some old playbooks. I noticed that the playbook include conditionals are evaluated before any variables have been loaded. This means if you do something like:

`

- include: other\_playbook.yml  
when: false  
`

you get the nice:

`  
skipping playbook include ‘other\_playbook.yml’ due to conditional test failure

`  
and the conditional doesn’t get applied to every task inside the playbook. This is great and prevents having potentially hundreds of skipped tasks for a playbook that never ran.

However, if you use a conditional with any variable in it, even something like:

`

- include:other\_playbook.yml  
when:“‘{{ ansible\_hostname }}’ | match(‘special\_server’)”  
`  
the code in playbook/playbook\_include.py will throw an AnsibleError when evaluating the conditional because ansible\_hostname is undefined. It then passes the conditional on to every task.

Besides the extra skipped output, we’ve run into issues where roles get marked skipped inside other\_playbook.yml and then aren’t run by a later playbook. This led to some allow\_duplicates being added to ensure the roles would be run the second time (which has led to some other complications with our upgrade to 2.x).

I’m curious if there’s a reason fact gathering couldn’t be done (if enabled) before playbook includes are evaluated to support better conditional includes. This would prevent a lot of skipped tasks and unnecessary allow\_duplicate usage in our situation. Or is there a better way to approach this in general?

Thanks,  
Thomas Brezinski
