From 7db849397cee0f502b7577dcceb2d5d8769fdc8b Mon Sep 17 00:00:00 2001 From: Philip Misiowiec Date: Fri, 26 Sep 2014 23:23:39 -0700 Subject: [PATCH] Ability to enable SSL when creating MongoDB users --- lib/ansible/modules/extras/database/mongodb_user.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/extras/database/mongodb_user.py b/lib/ansible/modules/extras/database/mongodb_user.py index 5d7e0897b6..4ff7ec2cb3 100644 --- a/lib/ansible/modules/extras/database/mongodb_user.py +++ b/lib/ansible/modules/extras/database/mongodb_user.py @@ -67,6 +67,10 @@ options: - The password to use for the user required: false default: null + ssl: + description: + - Whether to use an SSL connection when connecting to the database + default: False roles: version_added: "1.3" description: @@ -92,6 +96,9 @@ EXAMPLES = ''' # Create 'burgers' database user with name 'bob' and password '12345'. - 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'. - mongodb_user: database=burgers name=bob state=absent @@ -172,6 +179,7 @@ def main(): database=dict(required=True, aliases=['db']), user=dict(required=True, aliases=['name']), password=dict(aliases=['pass']), + ssl=dict(default=False), roles=dict(default=None, type='list'), state=dict(default='present', choices=['absent', 'present']), ) @@ -188,14 +196,15 @@ def main(): db_name = module.params['database'] user = module.params['user'] password = module.params['password'] + ssl = module.params['ssl'] roles = module.params['roles'] state = module.params['state'] try: 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: - 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: