From f6c887ccd0ab31258f8b911169f655abb91c8fac Mon Sep 17 00:00:00 2001 From: Tasya Aditya Rukmana Date: Wed, 19 Jul 2017 10:38:16 +0800 Subject: [PATCH 1/6] Add mongodb_write module and template --- playbooks/library/mongodb_write.py | 174 ++++++++++++++++++ roles/labsstats/tasks/main.yml | 5 + roles/labsstats/tests/library | Bin 0 -> 1004 bytes .../test_with_internet_connection_to_db.yml | 0 .../tests/test_with_ssh_connection_to_db.yml | 0 5 files changed, 179 insertions(+) create mode 100644 playbooks/library/mongodb_write.py create mode 100644 roles/labsstats/tasks/main.yml create mode 100644 roles/labsstats/tests/library create mode 100644 roles/labsstats/tests/test_with_internet_connection_to_db.yml create mode 100644 roles/labsstats/tests/test_with_ssh_connection_to_db.yml diff --git a/playbooks/library/mongodb_write.py b/playbooks/library/mongodb_write.py new file mode 100644 index 0000000..67e604e --- /dev/null +++ b/playbooks/library/mongodb_write.py @@ -0,0 +1,174 @@ +#!/usr/bin/python + +DOCUMENTATION = ''' +--- +module: mongodb_write +short_description: Writes to a MongoDB database. +description: + - Writes to a MongoDB database. +options: +''' + +import sys +try: + from pymongo.errors import ConnectionFailure + from pymongo.errors import OperationFailure + from pymongo import version as PyMongoVersion + from pymongo import MongoClient +except ImportError: + try: # for older PyMongo 2.2 + from pymongo import Connection as MongoClient + except ImportError: + pymongo_found = False + else: + pymongo_found = True +else: + pymongo_found = True + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.six.moves import +from distutils.version import LooseVersion + +# ========================================= +# MongoDB module specific support methods. +# + +def check_compatibility(module, client): + """Check the compatibility between the driver and the database. + See: https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#python-driver-compatibility + Args: + module: Ansible module. + client (cursor): Mongodb cursor on admin database. + """ + loose_srv_version = LooseVersion(client.server_info()['version']) + loose_driver_version = LooseVersion(PyMongoVersion) + + if loose_srv_version >= LooseVersion('3.2') and loose_driver_version < LooseVersion('3.2'): + module.fail_json(msg=' (Note: you must use pymongo 3.2+ with MongoDB >= 3.2)') + + elif loose_srv_version >= LooseVersion('3.0') and loose_driver_version <= LooseVersion('2.8'): + module.fail_json(msg=' (Note: you must use pymongo 2.8+ with MongoDB 3.0)') + + elif loose_srv_version >= LooseVersion('2.6') and loose_driver_version <= LooseVersion('2.7'): + module.fail_json(msg=' (Note: you must use pymongo 2.7+ with MongoDB 2.6)') + + elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'): + module.fail_json(msg=' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)') + +def check_database_found(module, client, db_name): + pass + +def load_mongocnf(): + config = configparser.RawConfigParser() + mongocnf = os.path.expanduser('~/.mongodb.cnf') + + try: + config.readfp(open(mongocnf)) + creds = dict( + user=config.get('client', 'user'), + password=config.get('client', 'pass') + ) + except (configparser.NoOptionError, IOError): + return False + + return creds + +def insert(module, client, db_name, db_object, data): + db = client[db_name] + + db[db_object].insert(data) + +def update_one(module, client, db_name, db_object, data): + db = client[db_name] + + db[db_object].update_one(data, upsert=False) + +def upsert(module, client, db_name, db_object, data): + pass + +# ========================================= +# Module execution. +# + +def main(): + module = AnsibleModule( + argument_spec = dict( + login_user=dict(default=None), + login_password=dict(default=None, no_log=True), + login_host=dict(default='localhost'), + login_port=dict(default='27017'), + login_database=dict(default=None), + database=dict(required=True, aliases=['db']), + db_object=dict(required=True), + action=dict(required=True, default='insert', choices=['insert', 'update', 'upsert']), + ) + ) + + if not pymongo_found: + module.fail_json(msg='the python pymongo module is required') + + login_user = module.params['login_user'] + login_password = module.params['login_user'] + login_host = module.params['login_host'] + login_port = module.params['login_port'] + login_database = module.params['login_database'] + + db_name = module.params['database'] + db_object = module.params['db_object'] + action = module.params['action'] + + try: + connection_params = { + "host": login_host, + "port": int(login_port), + } + + client = MongoClient(**connection_params) + + # NOTE: this check must be done ASAP. + # We don't need to be authenticated. + check_compatibility(module, client) + + if login_user is None and login_password is None: + mongocnf_creds = load_mongocnf() + if mongocnf_creds is not False: + login_user = mongocnf_creds['user'] + login_password = mongocnf_creds['password'] + elif login_password is None or login_user is None: + module.fail_json(msg='when supplying login arguments, both login_user and login_password must be provided') + + if login_user is not None and login_password is not None: + client.admin.authenticate(login_user, login_password, source=login_database) + elif LooseVersion(PyMongoVersion) >= LooseVersion('3.0'): + if db_name != "admin": + module.fail_json(msg='The localhost login exception only allows the first admin account to be created') + #else: this has to be the first admin user added + + except Exception: + e = get_exception() + module.fail_json(msg='unable to connect to database: %s' % str(e)) + + try: + if action == 'insert': + try: + insert(module, client, db_name, db_object, data) + except Exception: + e = get_exception() + module.fail_json(msg='Unable to insert to database: $s' % str(e)) + + elif action == 'update': + try: + update(module, client, db_name, db_object, data) + except Exception: + e = get_exception() + module.fail_json(msg='Unable to update to database: $s' % str(e)) + elif action == 'upsert': + try: + upsert(module, client, db_name, db_object, data) + except Exception: + e = get_exception() + module.fail_json(msg='Unable to upsert to database: $s' % str(e)) + +if __name__ == '__main__': + main() diff --git a/roles/labsstats/tasks/main.yml b/roles/labsstats/tasks/main.yml new file mode 100644 index 0000000..f480595 --- /dev/null +++ b/roles/labsstats/tasks/main.yml @@ -0,0 +1,5 @@ +- name: 'Update demo runs count' + +- name: 'Update number of runs per user' + +- name: 'Update unique user run count' diff --git a/roles/labsstats/tests/library b/roles/labsstats/tests/library new file mode 100644 index 0000000000000000000000000000000000000000..a1b671be07c3a4af8a7d2eba1b76fdc6033845b7 GIT binary patch literal 1004 zcmZvaPixdb7{(|4qb>BXwqkpb8j6SqLxSC|-O_{W?n)1OkybArnwS(r(@mMA(Ctm| zBlO_GgBQUMAmTx34?U`Q(2Mv1S`;jT;6YrUCw*g#bjXwWy?^q~J2Ua(cvWGnxjLI? z!PN79dIu_e>%>ks+fQD6pWJECwr>Ugqdr8z{mcUlVloV+mXbgx;32V7*ALUKtC`FA zomj7)5Js5=H!X5?;6{<_CBqUYTYj(>!_Ix{k=ymqGuJqo=Y^hjbyu0RQJhVa9cUi9 z0o{exp@$HA8$jRhmf1;Rk3Z!qh3!NmCHvDxr(}P;&@I_t{Q=Q~yAe33{090qR-WnO`Zi|X9rx;YLJyebb3SfpKU&Gp z Date: Wed, 19 Jul 2017 14:46:07 +0800 Subject: [PATCH 2/6] Fix authentication and folder shortcuts --- playbooks/library/mongodb_write.py | 135 ++++++++++-------- roles/labsstats/tasks/main.yml | 12 +- roles/labsstats/tests/library | Bin 1004 -> 27 bytes roles/labsstats/tests/roles | 1 + .../tests/test_with_ssh_connection_to_db.yml | 5 + 5 files changed, 88 insertions(+), 65 deletions(-) mode change 100644 => 120000 roles/labsstats/tests/library create mode 120000 roles/labsstats/tests/roles diff --git a/playbooks/library/mongodb_write.py b/playbooks/library/mongodb_write.py index 67e604e..f4419fb 100644 --- a/playbooks/library/mongodb_write.py +++ b/playbooks/library/mongodb_write.py @@ -1,5 +1,9 @@ #!/usr/bin/python +ANSIBLE_METADATA = {'metadata_version': '1.0', + 'status': ['preview'], + 'supported_by': 'community'} + DOCUMENTATION = ''' --- module: mongodb_write @@ -10,6 +14,9 @@ ''' import sys +import os +import json +import ast try: from pymongo.errors import ConnectionFailure from pymongo.errors import OperationFailure @@ -27,13 +34,14 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception -from ansible.module_utils.six.moves import +from ansible.module_utils.six.moves import configparser from distutils.version import LooseVersion # ========================================= # MongoDB module specific support methods. # + def check_compatibility(module, client): """Check the compatibility between the driver and the database. See: https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#python-driver-compatibility @@ -56,9 +64,11 @@ def check_compatibility(module, client): elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'): module.fail_json(msg=' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)') + def check_database_found(module, client, db_name): pass + def load_mongocnf(): config = configparser.RawConfigParser() mongocnf = os.path.expanduser('~/.mongodb.cnf') @@ -74,57 +84,60 @@ def load_mongocnf(): return creds -def insert(module, client, db_name, db_object, data): - db = client[db_name] +def insert(module, client, db_name, db_object, data): + db = client[db_name] db[db_object].insert(data) -def update_one(module, client, db_name, db_object, data): - db = client[db_name] +def update_one(module, client, db_name, db_object, data): + db = client[db_name] db[db_object].update_one(data, upsert=False) + def upsert(module, client, db_name, db_object, data): - pass + pass # ========================================= # Module execution. # + def main(): - module = AnsibleModule( - argument_spec = dict( - login_user=dict(default=None), - login_password=dict(default=None, no_log=True), - login_host=dict(default='localhost'), - login_port=dict(default='27017'), - login_database=dict(default=None), - database=dict(required=True, aliases=['db']), - db_object=dict(required=True), - action=dict(required=True, default='insert', choices=['insert', 'update', 'upsert']), - ) - ) - - if not pymongo_found: - module.fail_json(msg='the python pymongo module is required') - - login_user = module.params['login_user'] - login_password = module.params['login_user'] - login_host = module.params['login_host'] - login_port = module.params['login_port'] - login_database = module.params['login_database'] - - db_name = module.params['database'] - db_object = module.params['db_object'] - action = module.params['action'] - - try: + module = AnsibleModule( + argument_spec=dict( + login_user=dict(default=None), + login_password=dict(default=None, no_log=True), + login_host=dict(default='localhost'), + login_port=dict(default='27017'), + login_database=dict(default=None), + database=dict(required=True, aliases=['db']), + db_object=dict(required=True), + action=dict(required=True, choices=['insert', 'update', 'upsert']), + data=dict(required=True), + ) + ) + + if not pymongo_found: + module.fail_json(msg='the python pymongo module is required') + + login_user = module.params['login_user'] + login_password = module.params['login_password'] + login_host = module.params['login_host'] + login_port = module.params['login_port'] + login_database = module.params['login_database'] + + db_name = module.params['database'] + db_object = module.params['db_object'] + action = module.params['action'] + data = ast.literal_eval(module.params['data']) + + try: connection_params = { "host": login_host, "port": int(login_port), } - - client = MongoClient(**connection_params) + client = MongoClient("mongodb://"+login_user+":"+login_password+"@"+login_host+":"+login_port+"/"+db_name) # NOTE: this check must be done ASAP. # We don't need to be authenticated. @@ -135,40 +148,36 @@ def main(): if mongocnf_creds is not False: login_user = mongocnf_creds['user'] login_password = mongocnf_creds['password'] - elif login_password is None or login_user is None: - module.fail_json(msg='when supplying login arguments, both login_user and login_password must be provided') + elif login_password is None or login_user is None: + module.fail_json(msg='when supplying login arguments, both login_user and login_password must be provided') if login_user is not None and login_password is not None: - client.admin.authenticate(login_user, login_password, source=login_database) - elif LooseVersion(PyMongoVersion) >= LooseVersion('3.0'): - if db_name != "admin": - module.fail_json(msg='The localhost login exception only allows the first admin account to be created') - #else: this has to be the first admin user added + client[db_name].authenticate(login_user, login_password, source=login_database) except Exception: e = get_exception() module.fail_json(msg='unable to connect to database: %s' % str(e)) - - try: - if action == 'insert': - try: - insert(module, client, db_name, db_object, data) - except Exception: - e = get_exception() - module.fail_json(msg='Unable to insert to database: $s' % str(e)) - - elif action == 'update': - try: - update(module, client, db_name, db_object, data) - except Exception: - e = get_exception() - module.fail_json(msg='Unable to update to database: $s' % str(e)) - elif action == 'upsert': - try: - upsert(module, client, db_name, db_object, data) - except Exception: - e = get_exception() - module.fail_json(msg='Unable to upsert to database: $s' % str(e)) + if action == 'insert': + try: + insert(module, client, db_name, db_object, data) + except Exception: + e = get_exception() + module.fail_json(msg='Unable to insert to database: %s' % str(e)) + + elif action == 'update': + try: + update_one(module, client, db_name, db_object, data) + except Exception: + e = get_exception() + module.fail_json(msg='Unable to update to database: %s' % str(e)) + elif action == 'upsert': + try: + upsert(module, client, db_name, db_object, data) + except Exception: + e = get_exception() + module.fail_json(msg='Unable to upsert to database: %s' % str(e)) + + module.exit_json(changed=True) if __name__ == '__main__': main() diff --git a/roles/labsstats/tasks/main.yml b/roles/labsstats/tasks/main.yml index f480595..2f15240 100644 --- a/roles/labsstats/tasks/main.yml +++ b/roles/labsstats/tasks/main.yml @@ -1,5 +1,13 @@ +--- - name: 'Update demo runs count' + mongodb_write: + database: labs-stats + db_object: 'GlobalStats' + action: 'insert' + data: + name: 'test' + count: 0 -- name: 'Update number of runs per user' +# - name: 'Update number of runs per user' -- name: 'Update unique user run count' +# - name: 'Update unique user run count' diff --git a/roles/labsstats/tests/library b/roles/labsstats/tests/library deleted file mode 100644 index a1b671be07c3a4af8a7d2eba1b76fdc6033845b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1004 zcmZvaPixdb7{(|4qb>BXwqkpb8j6SqLxSC|-O_{W?n)1OkybArnwS(r(@mMA(Ctm| zBlO_GgBQUMAmTx34?U`Q(2Mv1S`;jT;6YrUCw*g#bjXwWy?^q~J2Ua(cvWGnxjLI? z!PN79dIu_e>%>ks+fQD6pWJECwr>Ugqdr8z{mcUlVloV+mXbgx;32V7*ALUKtC`FA zomj7)5Js5=H!X5?;6{<_CBqUYTYj(>!_Ix{k=ymqGuJqo=Y^hjbyu0RQJhVa9cUi9 z0o{exp@$HA8$jRhmf1;Rk3Z!qh3!NmCHvDxr(}P;&@I_t{Q=Q~yAe33{090qR-WnO`Zi|X9rx;YLJyebb3SfpKU&Gp z Date: Wed, 19 Jul 2017 17:49:07 +0800 Subject: [PATCH 3/6] Add filter for update and upsert, update tasks --- playbooks/library/mongodb_write.py | 17 +++++++------ roles/labsstats/tasks/main.yml | 38 ++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/playbooks/library/mongodb_write.py b/playbooks/library/mongodb_write.py index f4419fb..0476192 100644 --- a/playbooks/library/mongodb_write.py +++ b/playbooks/library/mongodb_write.py @@ -90,13 +90,14 @@ def insert(module, client, db_name, db_object, data): db[db_object].insert(data) -def update_one(module, client, db_name, db_object, data): +def update_one(module, client, db_name, db_object, row_filter, data): db = client[db_name] - db[db_object].update_one(data, upsert=False) + db[db_object].update_one(row_filter, data, upsert=False) -def upsert(module, client, db_name, db_object, data): - pass +def upsert(module, client, db_name, db_object, row_filter, data): + db = client[db_name] + db[db_object].update_one(row_filter, data, upsert=True) # ========================================= # Module execution. @@ -114,7 +115,8 @@ def main(): database=dict(required=True, aliases=['db']), db_object=dict(required=True), action=dict(required=True, choices=['insert', 'update', 'upsert']), - data=dict(required=True), + data=dict(default={}), + filter=dict(default={}), ) ) @@ -130,6 +132,7 @@ def main(): db_name = module.params['database'] db_object = module.params['db_object'] action = module.params['action'] + row_filter = module.params['filter'] data = ast.literal_eval(module.params['data']) try: @@ -166,13 +169,13 @@ def main(): elif action == 'update': try: - update_one(module, client, db_name, db_object, data) + update_one(module, client, db_name, db_object, row_filter, data) except Exception: e = get_exception() module.fail_json(msg='Unable to update to database: %s' % str(e)) elif action == 'upsert': try: - upsert(module, client, db_name, db_object, data) + upsert(module, client, db_name, db_object, row_filter, data) except Exception: e = get_exception() module.fail_json(msg='Unable to upsert to database: %s' % str(e)) diff --git a/roles/labsstats/tasks/main.yml b/roles/labsstats/tasks/main.yml index 2f15240..5c9286b 100644 --- a/roles/labsstats/tasks/main.yml +++ b/roles/labsstats/tasks/main.yml @@ -1,13 +1,41 @@ --- - name: 'Update demo runs count' mongodb_write: + login_user: "{{ db_user }}" + login_password: "{{ db_password }}" database: labs-stats db_object: 'GlobalStats' - action: 'insert' + action: 'update' + filter: + name: 'runs' data: - name: 'test' - count: 0 + $inc: + count: 1 -# - name: 'Update number of runs per user' +- name: 'Update number of runs per user' + mongodb_write: + login_user: "{{ db_user }}" + login_password: "{{ db_password }}" + database: labs-stats + db_object: 'UserRuns' + action: 'upsert' + filter: + username: "{{ labs_username }}" + data: + $set: + username: "{{ labs_username }}" + $inc: + count: 1 -# - name: 'Update unique user run count' +- name: 'Update unique user run count' + mongodb_write: + login_user: "{{ db_user }}" + login_password: "{{ db_password }}" + database: labs-stats + db_object: 'GlobalStats' + action: 'update' + filter: + name: 'unique_users' + data: + $inc: + count: 1 From 9c16103ec10bee2c4a8551b4813ee5226e6db20f Mon Sep 17 00:00:00 2001 From: tadityar Date: Tue, 25 Jul 2017 20:03:56 +0800 Subject: [PATCH 4/6] Add upsert content return and conditional for unique user insert --- playbooks/library/mongodb_write.py | 20 ++++++++++++-------- roles/labsstats/tasks/main.yml | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/playbooks/library/mongodb_write.py b/playbooks/library/mongodb_write.py index 0476192..c03ff7f 100644 --- a/playbooks/library/mongodb_write.py +++ b/playbooks/library/mongodb_write.py @@ -87,17 +87,17 @@ def load_mongocnf(): def insert(module, client, db_name, db_object, data): db = client[db_name] - db[db_object].insert(data) + return db[db_object].insert(data) def update_one(module, client, db_name, db_object, row_filter, data): db = client[db_name] - db[db_object].update_one(row_filter, data, upsert=False) + return db[db_object].update_one(row_filter, data, upsert=False) def upsert(module, client, db_name, db_object, row_filter, data): db = client[db_name] - db[db_object].update_one(row_filter, data, upsert=True) + return db[db_object].update_one(row_filter, data, upsert=True) # ========================================= # Module execution. @@ -132,8 +132,11 @@ def main(): db_name = module.params['database'] db_object = module.params['db_object'] action = module.params['action'] - row_filter = module.params['filter'] + # row_filter = module.params['filter'] + data = ast.literal_eval(module.params['data']) + row_filter = ast.literal_eval(module.params['filter']) + u_content = None try: connection_params = { @@ -162,25 +165,26 @@ def main(): module.fail_json(msg='unable to connect to database: %s' % str(e)) if action == 'insert': try: - insert(module, client, db_name, db_object, data) + raw_content = insert(module, client, db_name, db_object, data) except Exception: e = get_exception() module.fail_json(msg='Unable to insert to database: %s' % str(e)) elif action == 'update': try: - update_one(module, client, db_name, db_object, row_filter, data) + raw_content = update_one(module, client, db_name, db_object, row_filter, data) except Exception: e = get_exception() module.fail_json(msg='Unable to update to database: %s' % str(e)) elif action == 'upsert': try: - upsert(module, client, db_name, db_object, row_filter, data) + raw_content = upsert(module, client, db_name, db_object, row_filter, data) + u_content = raw_content.upserted_id except Exception: e = get_exception() module.fail_json(msg='Unable to upsert to database: %s' % str(e)) - module.exit_json(changed=True) + module.exit_json(changed=True, content=str(u_content)) if __name__ == '__main__': main() diff --git a/roles/labsstats/tasks/main.yml b/roles/labsstats/tasks/main.yml index 5c9286b..c306f3e 100644 --- a/roles/labsstats/tasks/main.yml +++ b/roles/labsstats/tasks/main.yml @@ -26,6 +26,7 @@ username: "{{ labs_username }}" $inc: count: 1 + register: upsert_result - name: 'Update unique user run count' mongodb_write: @@ -39,3 +40,4 @@ data: $inc: count: 1 + when: upsert_result != "None" From 868a4e34379a034e836c9c3c2f5ad0d2430a49cc Mon Sep 17 00:00:00 2001 From: tadityar Date: Tue, 25 Jul 2017 20:26:00 +0800 Subject: [PATCH 5/6] Add README and hook to prep-demo.yml --- roles/labsstats/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 roles/labsstats/README.md diff --git a/roles/labsstats/README.md b/roles/labsstats/README.md new file mode 100644 index 0000000..90eb728 --- /dev/null +++ b/roles/labsstats/README.md @@ -0,0 +1,32 @@ +Labs Stats +========== + +This role updates labs demo stats after each successful run. + +Requirements +------------ + +Mongodb must already be installed and running at the target server and loaded with the following schema. + +``` +{"name": "runs", "count": 0} +{"name": "unique_users", "count": 0} +``` + +To populate the database with the aforementioned schema, please create a new .json file with the above as the content and run + +``` +mongoimport --db --collection GlobalStats --drop --file ~/path/to/file.json +``` + +Role Variables +-------------- + +- `labs_username`: The labs username that we want to record in the database (currently pulled from `demo_username`). +- `db_user`: The database username that has write access to the database. +- `db_password`: The database user password. + +Running the Playbook +-------------------- + +`$ ansible-playbook playbooks/prep-demo.yml --ask-become-pass` if become is enabled \ No newline at end of file From 015fd547b3b2a6f1c74426b97262bac2545e01c2 Mon Sep 17 00:00:00 2001 From: Tasya Aditya Rukmana Date: Thu, 27 Jul 2017 14:28:16 +0800 Subject: [PATCH 6/6] Add documentation for mongodb_write --- playbooks/library/mongodb_write.py | 51 +++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/playbooks/library/mongodb_write.py b/playbooks/library/mongodb_write.py index c03ff7f..9e8ae7c 100644 --- a/playbooks/library/mongodb_write.py +++ b/playbooks/library/mongodb_write.py @@ -11,6 +11,56 @@ description: - Writes to a MongoDB database. options: + login_user: + description: + - The username used to authenticate with + required: false + default: null + login_password: + description: + - The password used to authenticate with + required: false + default: null + login_host: + login_host: + description: + - The host running the database + required: false + default: localhost + login_port: + login_port: + description: + - The port to connect to + required: false + default: 27017 + login_database: + description: + - The database where login credentials are stored + required: false + default: null + database: + description: + - The name of the database to write to + required: true + db_object: + description: + - The name of the mongodb Object in the database you want to write to + required: true + action: + description: + - The name of the write action + choices: ["insert", "update", "upsert"] + requiredL true + data: + description: + - A dictionary of data you want to write to the database + required: false + default: empty dict + filter: + description: + - A dictionary of writing filters + required: false + default: empty dict ''' import sys @@ -132,7 +182,6 @@ def main(): db_name = module.params['database'] db_object = module.params['db_object'] action = module.params['action'] - # row_filter = module.params['filter'] data = ast.literal_eval(module.params['data']) row_filter = ast.literal_eval(module.params['filter'])