Hi,
I know that when using conditionals on an include, ‘All the tasks get evaluated, but the conditional is applied to each and every task’. However this breaks when some of that tasks register variables and other tasks in the group use those variable.
Example:
main.yml:
- include: extra.yml
when: do_extra is defined
extra.yml:
- name: check if we can do task A
shell: check_if_task_A_possible
register: A_possible
ignore_errors: yes
- name: task A
shell: run_task_A
when: A_possible.rc == 0
Now if you run main.yml and ‘do_extra’ is not defined, the run will fail on ‘task A’ because when the ‘when’ condition is evaluated, the variable A_possible will not exist.
So you are saying the conditional in this case should be added above the other conditional, not below. That seems reasonable to me, as I can’t think of a case where that would be a bad thing.
Please make sure there is a github ticket filed to track this one and we can change it to insert rather than append.
I don’t think that is sufficient because right now it looks like the two conditions are compounded and tested together which will still fail because A_possible is not defined. I think you would have to run the file level conditional before the task level ones to keep this from happening.
Updated my original message with my above statement and added it as an issue to github.
https://github.com/ansible/ansible/issues/3539
Forgot about that, but …
If the conditional is compounded it will still have short circuit evaluation behavior.
I suspect it’s added to the end and not the start.
Ah, you’re right. That will be just fine.