Greetings fellow Ansible users!
I have a use case where I want to add values to a list dependant on host groups. I will then use the resulting list as an argument to another task.
It’s important than I don’t have duplicate values in the list, so I am using union() to add new items to the list, as indicated by http://docs.ansible.com/ansible/playbooks_filters.html
For some reason, as soon as a set_fact task is run against the same host and variable for a second time, Ansible explodes with an unintuitive Python/Jinja2 error, saying it’s getting a list when it doesn’t expect a list (which makes NO sense to me, because union() wants two lists are arguments surely?!).
fatal: [host4-uk] => Failed to template fruit=“{{ fruit | union([ ‘Goosberry’, ‘Blackberry’ ]) }}”: an unexpected type error occurred. Error was coercing to Unicode: need string or buffer, list found
Can anybody shed any light on this? Am I doing something particularly silly? Is there a better way to achieve what I want to do?
To illustrate the problem, I have tried to distill the issue down to this simple example:
nicola $ ls -1 *
fruit.yaml
inventory
group_vars:
all
nicola $ cat group_vars/all
fruit:
- UniversalFruit1-Foo
nicola $ cat inventory
[tropical]
host1-asia ansible_ssh_host=172.18.32.89
host2-asia ansible_ssh_host=172.18.97.157
[domestic]
host3-uk ansible_ssh_host=172.18.128.12
host4-uk ansible_ssh_host=172.18.128.13
[berries]
host4-uk ansible_ssh_host=172.18.128.13
nicola $ cat fruit.yaml