jinja template difference filter

Afternoon,

I have a template where I have a group of 4 IPs. I want to make a
list of the 3 IPs - These 3 IPs are for the other database systems,
so need to except the IP of the current database where the template is
being deployed. The line that does this is below, but over the can¹t
seem to get it working despite looking at it for a couple of years

/etc/ansible/roles/mysql/templates/template/galera.cnf.j2

Š.

wsrep_cluster_address=gcomm://{{databases | join(',') | difference
(ansible_ipv4.bond0)}};
Š..

When I run the playbook, it fails with the following error.

fatal: [192.168.149.241] => {'msg': "AnsibleUndefinedVariable: One or
more undefined variables: 'ansible_ipv4' is undefined", 'failed':
True}
fatal: [192.168.149.241] => {'msg': 'One or more items failed.',
'failed': True, 'changed': False, 'results': [{'msg':
"AnsibleUndefinedVariable: One or more undefined variables:
'ansible_ipv4' is undefined", 'failed':
True}]} FATAL: all hosts have already failed ‹ aborting

What would be the appropriate way to use difference filter to achieve
my goal here?

Regards,

William

Perhaps, you should have a look at run_once or/and delegated_to

Regards,

difference takes two lists, so

wsrep_cluster_address=gcomm://{{databases | difference([ansible_ipv4.bond0])}};

join(‘,’) creates a string, you want to use split (or if databases is a list already, nothing)
note the square brackets around ansible_ipv4.bond0, basically turning it into a list item.