I am trying to have a condition on a single item of a ‘with_items’ list but as i cannot do it directly, i found the following snippet:
-
name: prepare a list of common files that must be copied
set_fact: commonFiles=[‘1/f1’, ‘1/f2’] -
copy: src=“{{item}}” dest=2
with_items: “{{ commonFiles | union ( (1 == 2) | ternary ( [‘1/f3’], )) }}”
This gives me following error:
fatal: [this]: FAILED! => {“failed”: true, “msg”: “Unexpected templating type error occurred on ({{ commonFiles | union ( (1 == 2) | ternary ( [‘1/f3’], )) }}): coercing to Unicode: need string or buffer, list found”}
I am not sure why using a var of list types gives me an error, while the following works fine:
- copy: src=“{{item}}” dest=2
with_items: “{{ [‘1/f1’, ‘1/f2’] | union ( (1 == 2) | ternary ( [‘1/f3’], )) }}”