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

Commit a78312f

Browse files
Ensure that the password is not blank and add warning when use default passowrds
1 parent e4ddc3a commit a78312f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

tasks/main.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
---
2+
- name: Ensure users and passwords are defined
3+
assert:
4+
that:
5+
- mongodb_user_admin_name | length != 0
6+
- mongodb_user_admin_password | length != 0
7+
- mongodb_root_admin_name | length != 0
8+
- mongodb_root_admin_password | length != 0
9+
- mongodb_root_backup_name | length != 0
10+
- mongodb_root_backup_password | length != 0
11+
fail_msg: "Please set the user, password variables to Mongodb!"
212

313
- name: Check value of variable mongodb_net_ssl_host
414
fail:
515
msg: 'Set mongodb_net_ssl_mode is preferSSL or set valid hostname for mongodb_net_ssl_host!'
616
when: ( mongodb_net_ssl_mode == 'requireSSL'
7-
and mongodb_net_ssl_host == '' )
17+
and mongodb_net_ssl_host | length > 0 )
818

919
- name: Check value of variable mongodb_login_host
1020
fail:
@@ -13,6 +23,10 @@
1323
and mongodb_net_ssl_host != mongodb_login_host
1424
and not mongodb_replication_replset )
1525

26+
- name: Check if password is default
27+
include: warning_default_password.yml
28+
tags: [mongodb]
29+
1630
- name: Include OS-specific variables
1731
include_vars: "{{ item }}"
1832
with_first_found:

tasks/warning_default_password.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- name: Check passwords
3+
fail:
4+
msg: "[WARNING]: Using default password to user: {{ item.user }}"
5+
ignore_errors: yes
6+
loop:
7+
- user: "{{ mongodb_user_admin_name }}"
8+
password: "{{ mongodb_user_admin_password }}"
9+
- user: "{{ mongodb_root_admin_name }}"
10+
password: "{{ mongodb_root_admin_password }}"
11+
- user: "{{ mongodb_root_backup_name }}"
12+
password: "{{ mongodb_root_backup_password }}"
13+
when: item.password == "passw0rd"
14+
run_once: yes

0 commit comments

Comments
 (0)