Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 09e644d

Browse files
Add task to generate mongodb key in runtime
1 parent 8512ea9 commit 09e644d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tasks/configure.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@
2727
state: present
2828
when: mongodb_uid is defined
2929

30+
- name: Generate mongodb key
31+
command: openssl rand -base64 756
32+
register: mongodb_key
33+
run_once: True
34+
when: mongodb_replication_replset | length > 0 and not mongodb_keyfile_content
35+
3036
- name: Create keyFile
3137
copy:
3238
dest: "{{ mongodb_security_keyfile }}"
33-
content: "{{ mongodb_keyfile_content }}"
39+
content: "{{ mongodb_key.stdout_lines|join('\n') if (not mongodb_keyfile_content) else mongodb_keyfile_content }}"
3440
owner: "{{ mongodb_user }}"
3541
group: "root"
3642
mode: 0600
43+
force: "{{ mongodb_keyfile_force_renew }}"
3744
when: mongodb_replication_replset | length > 0
3845

3946
- name: Create log dir if missing

0 commit comments

Comments
 (0)