Skip to content

Commit 8a4f07e

Browse files
committed
Merge pull request ansible#2 from atlashealth/mongodb_ssl
Ability to enable SSL when creating MongoDB users
2 parents 6b431b1 + 6df1aa6 commit 8a4f07e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

database/mongodb_user.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
- The password to use for the user
6868
required: false
6969
default: null
70+
ssl:
71+
version_added: "1.8"
72+
description:
73+
- Whether to use an SSL connection when connecting to the database
74+
default: False
7075
roles:
7176
version_added: "1.3"
7277
description:
@@ -92,6 +97,9 @@
9297
# Create 'burgers' database user with name 'bob' and password '12345'.
9398
- mongodb_user: database=burgers name=bob password=12345 state=present
9499
100+
# Create a database user via SSL (MongoDB must be compiled with the SSL option and configured properly)
101+
- mongodb_user: database=burgers name=bob password=12345 state=present ssl=True
102+
95103
# Delete 'burgers' database user with name 'bob'.
96104
- mongodb_user: database=burgers name=bob state=absent
97105
@@ -172,6 +180,7 @@ def main():
172180
database=dict(required=True, aliases=['db']),
173181
user=dict(required=True, aliases=['name']),
174182
password=dict(aliases=['pass']),
183+
ssl=dict(default=False),
175184
roles=dict(default=None, type='list'),
176185
state=dict(default='present', choices=['absent', 'present']),
177186
)
@@ -188,14 +197,15 @@ def main():
188197
db_name = module.params['database']
189198
user = module.params['user']
190199
password = module.params['password']
200+
ssl = module.params['ssl']
191201
roles = module.params['roles']
192202
state = module.params['state']
193203

194204
try:
195205
if replica_set:
196-
client = MongoClient(login_host, int(login_port), replicaset=replica_set)
206+
client = MongoClient(login_host, int(login_port), replicaset=replica_set, ssl=ssl)
197207
else:
198-
client = MongoClient(login_host, int(login_port))
208+
client = MongoClient(login_host, int(login_port), ssl=ssl)
199209

200210
# try to authenticate as a target user to check if it already exists
201211
try:

0 commit comments

Comments
 (0)