# Unable to union another list to a list variable

**URL:** <https://forum.ansible.com/t/unable-to-union-another-list-to-a-list-variable/23953>\
**Category:** Ansible Project\
**Created:** [March 13, 2017, 6:08pm UTC](https://forum.ansible.com/t/unable-to-union-another-list-to-a-list-variable/23953 "2017-03-13T18:08:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [March 13, 2017, 6:08pm UTC](https://forum.ansible.com/t/unable-to-union-another-list-to-a-list-variable/23953/1 "2017-03-13T18:08:37Z")

</div>

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’], )) }}”

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 13, 2017, 7:17pm UTC](https://forum.ansible.com/t/unable-to-union-another-list-to-a-list-variable/23953/2 "2017-03-13T19:17:57Z")

</div>

commonFiles will be a string when using Ansible key value format and the value contain a space.

I recommend using the YAML format.

- name: prepare a list of common files that must be copied  
&nbsp;&nbsp;&nbsp;set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commonFiles: ['1/f1', '1/f2']

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [March 14, 2017, 10:08am UTC](https://forum.ansible.com/t/unable-to-union-another-list-to-a-list-variable/23953/3 "2017-03-14T10:08:21Z")

</div>

Thanks, That worked fine. Although i still don’t understand what just happened. You say that earlier it was taking commonFiles as string bu the error message says ‘expecting string found list’.
