From 5ce463551aeda103d218d4bc66347facaa625fcf Mon Sep 17 00:00:00 2001 From: Vincent Legoll Date: Thu, 13 Mar 2025 13:54:52 +0100 Subject: [PATCH] Fix ansible `difference()` filter use The `difference()` filter inputs a list, and takes another list as parameter, computes a set difference between the two, and returns the resulting (unordered) list. This is documented here: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/difference_filter.html This filter was changed in: https://github.com/ansible/ansible/commit/7d3d4572edcb4e436883a9aca2859f620077390a The behaviour changed in ansible-core between 2.15 and 2.16: ``` ################################################################ ### Testing ansible-core==2.16 ################################################################ PLAY [Test ansible difference filter] ****************************************** TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "diff with a string: ['one', 'two', 'six'] | difference('two') => ['one', 'six', 'two']" } TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "diff with a list: ['one', 'two', 'six'] | difference(['two']) => ['one', 'six']" } PLAY RECAP ********************************************************************* localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ################################################################ ### Testing ansible-core==2.15 ################################################################ PLAY [Test ansible difference filter] ****************************************** TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "diff with a string: ['one', 'two', 'six'] | difference('two') => ['one', 'six']" } TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "diff with a list: ['one', 'two', 'six'] | difference(['two']) => ['one', 'six']" } PLAY RECAP ********************************************************************* localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` The above was generated by using: https://github.com/vincent-legoll/test_ansible_diff Closes-Bug: #2096936 Change-Id: I7a57c829803fc5baa8b1d3a1805c102f04b8ab2c Signed-off-by: Vincent Legoll (cherry picked from commit ca89c07cd4f1b187460630f2ccb308e02815065e) --- templates/nova.conf.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/nova.conf.j2 b/templates/nova.conf.j2 index b291e0a7..f652d92e 100644 --- a/templates/nova.conf.j2 +++ b/templates/nova.conf.j2 @@ -211,7 +211,7 @@ memcache_security_strategy = ENCRYPT memcache_secret_key = {{ memcached_encryption_key }} {% endif %} -{% if group_names | intersect(nova_services.keys() | difference('nova-compute') | map('extract', nova_services, 'group') | list) | count > 0 %} +{% if group_names | intersect(nova_services.keys() | difference(['nova-compute']) | map('extract', nova_services, 'group') | list) | count > 0 %} [database] connection = mysql+pymysql://{{ nova_galera_user }}:{{ nova_container_mysql_password }}@{{ nova_galera_address }}:{{ nova_galera_port }}/{{ nova_galera_database }}?charset=utf8{% if nova_galera_use_ssl | bool %}&ssl_verify_cert=true{% if nova_galera_ssl_ca_cert | length > 0 %}&ssl_ca={{ nova_galera_ssl_ca_cert }}{% endif %}{% endif %}