From 9c4ff72a6c3d1022a0c02e26c41ecefdb7bc282a Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Mon, 22 Jul 2024 16:34:13 +0200 Subject: [PATCH] Ensure that first/last host detection is deterministic With ansible-core 2.16 a breaking changes landed [1] to some filters making their result returned in arbitrary order. With that, we were relying on them to always return exactly same ordered lists. With that we need to ensure that we still have determenistic behaviour where this is important. [1] https://github.com/ansible/ansible/issues/82554 Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/927841 Change-Id: I9b0c090d69bd9a86da9f8d877a4c561b22f8a028 --- tasks/main.yml | 9 +++------ tasks/zun_post_install.yml | 3 +-- vars/main.yml | 6 ++++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index b88d498..006cdf5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -90,8 +90,7 @@ - common-mq - zun-config when: - - "zun_services['zun-api']['group'] in group_names" - - "inventory_hostname == ((groups[zun_services['zun-api']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - _zun_is_first_play_host vars: _oslomsg_rpc_setup_host: "{{ zun_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ zun_oslomsg_rpc_userid }}" @@ -128,8 +127,7 @@ - username: "{{ zun_galera_user }}" password: "{{ zun_galera_password }}" when: - - "zun_services['zun-api']['group'] in group_names" - - "inventory_hostname == ((groups['zun_api'] | intersect(ansible_play_hosts)) | list)[0]" + - _zun_is_first_play_host tags: - always @@ -169,8 +167,7 @@ type: "{{ zun_service_type }}" description: "{{ zun_service_description }}" when: - - "zun_services['zun-api']['group'] in group_names" - - "inventory_hostname == ((groups['zun_api'] | intersect(ansible_play_hosts)) | list)[0]" + - _zun_is_first_play_host tags: - always diff --git a/tasks/zun_post_install.yml b/tasks/zun_post_install.yml index e7b0795..abf0da6 100644 --- a/tasks/zun_post_install.yml +++ b/tasks/zun_post_install.yml @@ -84,5 +84,4 @@ become_user: "{{ zun_system_user_name }}" changed_when: false when: - - zun_services['zun-api']['group'] in group_names - - inventory_hostname == ((groups['zun_api'] | intersect(ansible_play_hosts)) | list)[0] + - _zun_is_first_play_host diff --git a/vars/main.yml b/vars/main.yml index dbfa38e..70e7953 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -13,6 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +_zun_is_first_play_host: >- + {{ + (zun_services['zun-api']['group'] in group_names and + inventory_hostname == groups[zun_services['zun-api']['group']] | select('in', ansible_play_hosts) | first) | bool + }} + _zun_oslomsg_rpc_vhost_conf: >- {{ (zun_oslomsg_rpc_vhost is string) | ternary(