From 9e801d9edbaebc9a63f4530ccf51c21bb995c6fb Mon Sep 17 00:00:00 2001 From: Marcos Dias Date: Wed, 8 Jan 2025 18:24:11 -0300 Subject: [PATCH] Update main.yml --- roles/mongodb_auth/tasks/main.yml | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/roles/mongodb_auth/tasks/main.yml b/roles/mongodb_auth/tasks/main.yml index 2633b08..feb952f 100644 --- a/roles/mongodb_auth/tasks/main.yml +++ b/roles/mongodb_auth/tasks/main.yml @@ -20,43 +20,43 @@ - name: Generate the replica set key on the first defined MongoDB node ansible.builtin.set_fact: - replica_set_key: "{{ 768 | random | to_uuid | replace('-', '') | b64encode }}" + replica_set_key: "{{ 768 | random | to_uuid | replace('-', '') | b64encode }}" when: - - inventory_hostname == groups['mongodb'][0] - - mongodb_replication | bool + - inventory_hostname == groups['mongodb'][0] + - mongodb_replication | bool run_once: true - name: Save the generated key to first node ansible.builtin.copy: - content: "{{ replica_set_key }}" - dest: /etc/ssl/mongo-replicaset-key.pem - owner: "{{ mongo_owner }}" - group: "{{ mongo_group }}" - mode: '0400' + content: "{{ replica_set_key }}" + dest: /etc/ssl/mongo-replicaset-key.pem + owner: "{{ mongo_owner }}" + group: "{{ mongo_group }}" + mode: '0400' when: - - inventory_hostname == groups['mongodb'][0] - - mongodb_replication | bool + - inventory_hostname == groups['mongodb'][0] + - mongodb_replication | bool run_once: true - name: Fetch the key from the first MongoDB node ansible.builtin.slurp: - src: /etc/ssl/mongo-replicaset-key.pem + src: /etc/ssl/mongo-replicaset-key.pem register: slurped_key when: - - inventory_hostname == groups['mongodb'][0] - - mongodb_replication | bool + - inventory_hostname == groups['mongodb'][0] + - mongodb_replication | bool run_once: true - name: Distribute the key to all other nodes ansible.builtin.copy: - content: "{{ slurped_key.content | b64decode }}" - dest: /etc/ssl/mongo-replicaset-key.pem - owner: "{{ mongo_owner }}" - group: "{{ mongo_group }}" - mode: '0400' + content: "{{ slurped_key.content | b64decode }}" + dest: /etc/ssl/mongo-replicaset-key.pem + owner: "{{ mongo_owner }}" + group: "{{ mongo_group }}" + mode: '0400' when: - - inventory_hostname != groups['mongodb'][0] - - mongodb_replication | bool + - inventory_hostname != groups['mongodb'][0] + - mongodb_replication | bool - name: Check the auth status ansible.builtin.include_role: