I am attempting to create a unique list of values between two lists and I am creating a set based on the documentation described here http://docs.ansible.com/playbooks_variables.html#set-theory-filters
According to the documentation:
To get a union of two lists:
{{ list1 | union(list2) }}
Therefore I am attempting this in my playbook:
- name: A
set_fact:
listA: “{{test1.stdout.split()}}”
listB: “{{test2.stdout.split()}}”
Test1 and Test2 output a list object and have been verified. The above produces two lists as an example lets assume:
listA = [‘apple’, ‘orange’, ‘tree’, ‘pear’]
listB = [‘tree’, ‘orange’]
Now I want to get a union of both listA and listB
- name: B
set_fact: test=“{{listA | union(listB) }}”
This produces the result below:
{“ansible_facts”: {“test”: “set([“tree”, “orange”])”}, “item”: “”}
My problem is the fact test is assigned a string value of “set([“tree”, “orange”])” and not the set object, I need to operate on the set object. Can this be done? If not is there any other way within Ansible to get a unique list from two lists?