Merge pull request #2 from atlashealth/mongodb_ssl

Ability to enable SSL when creating MongoDB users
This commit is contained in:
Michael DeHaan 2014-10-01 14:23:51 -04:00
commit 8a4f07eecd

View file

@ -67,6 +67,11 @@ options:
- The password to use for the user - The password to use for the user
required: false required: false
default: null default: null
ssl:
version_added: "1.8"
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 +97,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 +180,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 +197,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: