From f7545420a6dcb0dbbfad82c97c26c489f1c00c93 Mon Sep 17 00:00:00 2001 From: Julien Georges Date: Mon, 17 Feb 2025 17:20:54 +0100 Subject: [PATCH] Bug #14312: Reset mongo_nodes facts. Otherwise, while executing 2 roles in the same play, the variable will contain the double of values than expected. --- deployment/roles/mongo/tasks/main.yml | 8 ++++++-- deployment/roles/mongo_init/tasks/main.yml | 8 ++++++-- .../roles/reinit_security_certificates/tasks/main.yml | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/deployment/roles/mongo/tasks/main.yml b/deployment/roles/mongo/tasks/main.yml index 68f7a99c62a..a2fa6bb07b2 100644 --- a/deployment/roles/mongo/tasks/main.yml +++ b/deployment/roles/mongo/tasks/main.yml @@ -179,11 +179,15 @@ - import_tasks: check_auth.yml # Create the local shard admin user + - name: Unset mongo_nodes fact + set_fact: + mongo_nodes: [] + - name: Compute list of mongo_nodes set_fact: - mongo_nodes: "{{ mongo_nodes | default([]) + [ hostvars[item]['ip_service'] + ':' + mongodb.mongod_port | string ] }}" + mongo_nodes: "{{ mongo_nodes + [ hostvars[item]['ip_service'] + ':' + mongodb.mongod_port | string ] }}" loop: "{{ groups['hosts_vitamui_mongod'] }}" - when: hostvars[item]['mongo_arbiter'] | default(false) | bool == false + when: not hostvars[item]['mongo_arbiter'] | default(false) | bool - name: Copy the script which create the local users template: diff --git a/deployment/roles/mongo_init/tasks/main.yml b/deployment/roles/mongo_init/tasks/main.yml index fefa1349469..8ccb757af85 100644 --- a/deployment/roles/mongo_init/tasks/main.yml +++ b/deployment/roles/mongo_init/tasks/main.yml @@ -5,11 +5,15 @@ - fail: msg="Variable '{{ mongod_source_template_dir }}' is not defined" when: mongod_source_template_dir is undefined + - name: Unset mongo_nodes fact + set_fact: + mongo_nodes: [] + - name: Compute list of mongo nodes set_fact: - mongo_nodes: "{{ mongo_nodes | default([]) + [ hostvars[item]['ip_service'] + ':'+ mongodb.mongod_port | string ] }}" + mongo_nodes: "{{ mongo_nodes + [ hostvars[item]['ip_service'] + ':' + mongodb.mongod_port | string ] }}" loop: "{{ groups['hosts_vitamui_mongod'] }}" - when: hostvars[item]['mongo_arbiter'] | default(false) | bool == false + when: not hostvars[item]['mongo_arbiter'] | default(false) | bool - name: Set Mongo URI set_fact: diff --git a/deployment/roles/reinit_security_certificates/tasks/main.yml b/deployment/roles/reinit_security_certificates/tasks/main.yml index 1964169cb5c..2a298860891 100644 --- a/deployment/roles/reinit_security_certificates/tasks/main.yml +++ b/deployment/roles/reinit_security_certificates/tasks/main.yml @@ -1,10 +1,14 @@ --- +- name: Unset mongo_nodes fact + set_fact: + mongo_nodes: [] + - name: Compute list of mongo nodes set_fact: - mongo_nodes: "{{ mongo_nodes | default([]) + [ hostvars[item]['ip_service'] + ':'+ mongodb.mongod_port | string ] }}" + mongo_nodes: "{{ mongo_nodes + [ hostvars[item]['ip_service'] + ':' + mongodb.mongod_port | string ] }}" loop: "{{ groups['hosts_vitamui_mongod'] }}" - when: hostvars[item]['mongo_arbiter'] | default(false) | bool == false + when: not hostvars[item]['mongo_arbiter'] | default(false) | bool - name: Set Mongo URI and credentials set_fact: