ansible 2.9.6
I have a list of hashes within with_items. And I put when as one of the items params.
So, the some items will be executed, some not. I don't want to declare or set defaults for the variables in skipped items. But i have "VAR_2 is undefined" error even for items that will not be executed.
Example:
---
- hosts: localhost
gather_facts: no
tasks:
- name: localtest
template:
src: test.txt.j2
dest: "{{ item.BASE_NAME }}-test.txt"
when: "item.when"
with_items:
- { BASE_NAME: "{{VAR_1}}", when: "{{ variable_true }}" }
- { BASE_NAME: "{{VAR_2}}", when: "{{ variable_false }}" }
- { BASE_NAME: "{{VAR_3}}", when: "{{ variable_true }}" }
I don't want to use defaults, because I'm using this Play for the different hosts with different variables sets. And I need errors, when necessary variable (with when true condition) is undeclared.