salt.modules.mongodb

Module to provide MongoDB functionality to Salt

configuration:

This module uses PyMongo, and accepts configuration details as parameters as well as configuration settings:

mongodb.host: 'localhost'
mongodb.port: 27017
mongodb.user: ''
mongodb.password: ''

This data can also be passed into pillar. Options passed into opts will overwrite options passed into pillar.

salt.modules.mongodb.db_exists(name, user=None, password=None, host=None, port=None)

Checks if a database exists in Mongodb

CLI Example:

salt '*' mongodb.db_exists <name> <user> <password> <host> <port>
salt.modules.mongodb.db_list(user=None, password=None, host=None, port=None)

List all Mongodb databases

CLI Example:

salt '*' mongodb.db_list <user> <password> <host> <port>
salt.modules.mongodb.db_remove(name, user=None, password=None, host=None, port=None)

Remove a Mongodb database

CLI Example:

salt '*' mongodb.db_remove <name> <user> <password> <host> <port>
salt.modules.mongodb.find(collection, query=None, user=None, password=None, host=None, port=None, database='admin')
salt.modules.mongodb.insert(objects, collection, user=None, password=None, host=None, port=None, database='admin')

Insert an object or list of objects into a collection

CLI Example:

salt '*' mongodb.insert '[{"foo": "FOO", "bar": "BAR"}, {"foo": "BAZ", "bar": "BAM"}]' mycollection <user> <password> <host> <port> <database>
salt.modules.mongodb.remove(collection, query=None, user=None, password=None, host=None, port=None, database='admin', w=1)

Remove an object or list of objects into a collection

CLI Example:

salt '*' mongodb.remove mycollection '[{"foo": "FOO", "bar": "BAR"}, {"foo": "BAZ", "bar": "BAM"}]' <user> <password> <host> <port> <database>
salt.modules.mongodb.user_create(name, passwd, user=None, password=None, host=None, port=None, database='admin')

Create a Mongodb user

CLI Example:

salt '*' mongodb.user_create <name> <user> <password> <host> <port> <database>
salt.modules.mongodb.user_exists(name, user=None, password=None, host=None, port=None, database='admin')

Checks if a user exists in Mongodb

CLI Example:

salt '*' mongodb.user_exists <name> <user> <password> <host> <port> <database>
salt.modules.mongodb.user_grant_roles(name, roles, database, user=None, password=None, host=None, port=None)

Grant one or many roles to a Mongodb user

CLI Examples:

salt '*' mongodb.user_grant_roles johndoe '["readWrite"]' dbname admin adminpwd localhost 27017
salt '*' mongodb.user_grant_roles janedoe '[{"role": "readWrite", "db": "dbname" }, {"role": "read", "db": "otherdb"}]' dbname admin adminpwd localhost 27017
salt.modules.mongodb.user_list(user=None, password=None, host=None, port=None, database='admin')

List users of a Mongodb database

CLI Example:

salt '*' mongodb.user_list <user> <password> <host> <port> <database>
salt.modules.mongodb.user_remove(name, user=None, password=None, host=None, port=None, database='admin')

Remove a Mongodb user

CLI Example:

salt '*' mongodb.user_remove <name> <user> <password> <host> <port> <database>
salt.modules.mongodb.user_revoke_roles(name, roles, database, user=None, password=None, host=None, port=None)

Revoke one or many roles to a Mongodb user

CLI Examples:

salt '*' mongodb.user_revoke_roles johndoe '["readWrite"]' dbname admin adminpwd localhost 27017
salt '*' mongodb.user_revoke_roles janedoe '[{"role": "readWrite", "db": "dbname" }, {"role": "read", "db": "otherdb"}]' dbname admin adminpwd localhost 27017
salt.modules.mongodb.user_roles_exists(name, roles, database, user=None, password=None, host=None, port=None)

Checks if a user of a Mongodb database has specified roles

CLI Examples:

salt '*' mongodb.user_roles_exists johndoe '["readWrite"]' dbname admin adminpwd localhost 27017
salt '*' mongodb.user_roles_exists johndoe '[{"role": "readWrite", "db": "dbname" }, {"role": "read", "db": "otherdb"}]' dbname admin adminpwd localhost 27017