Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Madias2222 committed Jan 8, 2025
1 parent 0fb8931 commit 9e801d9
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions roles/mongodb_auth/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9e801d9

Please sign in to comment.