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