Skip to content

Commit 1c0965c

Browse files
author
Philip Misiowiec
committed
Ability to enable SSL when creating MongoDB users
1 parent d2d0ed2 commit 1c0965c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

database/mongodb_user.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
- The password to use for the user
6868
required: false
6969
default: null
70+
ssl:
71+
description:
72+
- Whether to use an SSL connection when connecting to the database
73+
default: False
7074
roles:
7175
version_added: "1.3"
7276
description:
@@ -92,6 +96,9 @@
9296
# Create 'burgers' database user with name 'bob' and password '12345'.
9397
- mongodb_user: database=burgers name=bob password=12345 state=present
9498
99+
# Create a database user via SSL (MongoDB must be compiled with the SSL option and configured properly)
100+
- mongodb_user: database=burgers name=bob password=12345 state=present ssl=True
101+
95102
# Delete 'burgers' database user with name 'bob'.
96103
- mongodb_user: database=burgers name=bob state=absent
97104
@@ -172,6 +179,7 @@ def main():
172179
database=dict(required=True, aliases=['db']),
173180
user=dict(required=True, aliases=['name']),
174181
password=dict(aliases=['pass']),
182+
ssl=dict(default=False),
175183
roles=dict(default=None, type='list'),
176184
state=dict(default='present', choices=['absent', 'present']),
177185
)
@@ -188,14 +196,15 @@ def main():
188196
db_name = module.params['database']
189197
user = module.params['user']
190198
password = module.params['password']
199+
ssl = module.params['ssl']
191200
roles = module.params['roles']
192201
state = module.params['state']
193202

194203
try:
195204
if replica_set:
196-
client = MongoClient(login_host, int(login_port), replicaset=replica_set)
205+
client = MongoClient(login_host, int(login_port), replicaset=replica_set, ssl=ssl)
197206
else:
198-
client = MongoClient(login_host, int(login_port))
207+
client = MongoClient(login_host, int(login_port), ssl=ssl)
199208

200209
# try to authenticate as a target user to check if it already exists
201210
try:

0 commit comments

Comments
 (0)