Ability to enable SSL when creating MongoDB users
This commit is contained in:
parent
2a8fc63645
commit
7db849397c
1 changed files with 11 additions and 2 deletions
|
@ -67,6 +67,10 @@ options:
|
||||||
- The password to use for the user
|
- The password to use for the user
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
ssl:
|
||||||
|
description:
|
||||||
|
- Whether to use an SSL connection when connecting to the database
|
||||||
|
default: False
|
||||||
roles:
|
roles:
|
||||||
version_added: "1.3"
|
version_added: "1.3"
|
||||||
description:
|
description:
|
||||||
|
@ -92,6 +96,9 @@ EXAMPLES = '''
|
||||||
# Create 'burgers' database user with name 'bob' and password '12345'.
|
# Create 'burgers' database user with name 'bob' and password '12345'.
|
||||||
- mongodb_user: database=burgers name=bob password=12345 state=present
|
- mongodb_user: database=burgers name=bob password=12345 state=present
|
||||||
|
|
||||||
|
# Create a database user via SSL (MongoDB must be compiled with the SSL option and configured properly)
|
||||||
|
- mongodb_user: database=burgers name=bob password=12345 state=present ssl=True
|
||||||
|
|
||||||
# Delete 'burgers' database user with name 'bob'.
|
# Delete 'burgers' database user with name 'bob'.
|
||||||
- mongodb_user: database=burgers name=bob state=absent
|
- mongodb_user: database=burgers name=bob state=absent
|
||||||
|
|
||||||
|
@ -172,6 +179,7 @@ def main():
|
||||||
database=dict(required=True, aliases=['db']),
|
database=dict(required=True, aliases=['db']),
|
||||||
user=dict(required=True, aliases=['name']),
|
user=dict(required=True, aliases=['name']),
|
||||||
password=dict(aliases=['pass']),
|
password=dict(aliases=['pass']),
|
||||||
|
ssl=dict(default=False),
|
||||||
roles=dict(default=None, type='list'),
|
roles=dict(default=None, type='list'),
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present']),
|
||||||
)
|
)
|
||||||
|
@ -188,14 +196,15 @@ def main():
|
||||||
db_name = module.params['database']
|
db_name = module.params['database']
|
||||||
user = module.params['user']
|
user = module.params['user']
|
||||||
password = module.params['password']
|
password = module.params['password']
|
||||||
|
ssl = module.params['ssl']
|
||||||
roles = module.params['roles']
|
roles = module.params['roles']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if replica_set:
|
if replica_set:
|
||||||
client = MongoClient(login_host, int(login_port), replicaset=replica_set)
|
client = MongoClient(login_host, int(login_port), replicaset=replica_set, ssl=ssl)
|
||||||
else:
|
else:
|
||||||
client = MongoClient(login_host, int(login_port))
|
client = MongoClient(login_host, int(login_port), ssl=ssl)
|
||||||
|
|
||||||
# try to authenticate as a target user to check if it already exists
|
# try to authenticate as a target user to check if it already exists
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue