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'], [])) }}"

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c7e1b3d1-6b59-44ab-9400-eb8dbfdaca82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to