Changed description in mongodb_replication module
This commit is contained in:
parent
527214bcc9
commit
454df2ef69
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# (c) 2015, Sergei Antipov
|
# (c) 2015, Sergei Antipov, 2GIS LLC
|
||||||
#
|
#
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
#
|
#
|
||||||
|
@ -20,10 +20,9 @@
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: mongodb_replication
|
module: mongodb_replication
|
||||||
short_description: Adds or removes a user from a MongoDB database.
|
short_description: Adds or removes a node from a MongoDB Replica Set.
|
||||||
description:
|
description:
|
||||||
- Adds or removes a user from a MongoDB database.
|
- Adds or removes host from a MongoDB replica set. Initialize replica set if it needed.
|
||||||
version_added: "1.1"
|
|
||||||
options:
|
options:
|
||||||
login_user:
|
login_user:
|
||||||
description:
|
description:
|
||||||
|
@ -46,37 +45,29 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: 27017
|
default: 27017
|
||||||
replica_set:
|
replica_set:
|
||||||
version_added: "1.6"
|
|
||||||
description:
|
description:
|
||||||
- Replica set to connect to (automatically connects to primary for writes)
|
- Replica set to connect to (automatically connects to primary for writes)
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
database:
|
host_name:
|
||||||
description:
|
description:
|
||||||
- The name of the database to add/remove the user from
|
- The name of the host to add/remove from replica set
|
||||||
required: true
|
required: true
|
||||||
user:
|
host_port:
|
||||||
description:
|
description:
|
||||||
- The name of the user to add or remove
|
- The port of the host
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
password:
|
host_type:
|
||||||
description:
|
description:
|
||||||
- The password to use for the user
|
- The type of the host in replica set
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: replica
|
||||||
|
choices: [ "replica", "arbiter" ]
|
||||||
ssl:
|
ssl:
|
||||||
version_added: "1.8"
|
|
||||||
description:
|
description:
|
||||||
- Whether to use an SSL connection when connecting to the database
|
- Whether to use an SSL connection when connecting to the database
|
||||||
default: False
|
default: False
|
||||||
roles:
|
|
||||||
version_added: "1.3"
|
|
||||||
description:
|
|
||||||
- "The database user roles valid values are one or more of the following: read, 'readWrite', 'dbAdmin', 'userAdmin', 'clusterAdmin', 'readAnyDatabase', 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'dbAdminAnyDatabase'"
|
|
||||||
- This param requires mongodb 2.4+ and pymongo 2.5+
|
|
||||||
required: false
|
|
||||||
default: "readWrite"
|
|
||||||
state:
|
state:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
|
@ -88,26 +79,24 @@ notes:
|
||||||
- Requires the pymongo Python package on the remote host, version 2.4.2+. This
|
- Requires the pymongo Python package on the remote host, version 2.4.2+. This
|
||||||
can be installed using pip or the OS package manager. @see http://api.mongodb.org/python/current/installation.html
|
can be installed using pip or the OS package manager. @see http://api.mongodb.org/python/current/installation.html
|
||||||
requirements: [ "pymongo" ]
|
requirements: [ "pymongo" ]
|
||||||
author: Elliott Foster
|
author: Sergei Antipov
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Create 'burgers' database user with name 'bob' and password '12345'.
|
# Add 'mongo1.dev:27017' host into replica set as replica (Replica will be initiated if it not exists)
|
||||||
- mongodb_user: database=burgers name=bob password=12345 state=present
|
- mongodb_replication: replica_set=replSet host_name=mongo1.dev host_port=27017 state=present
|
||||||
|
|
||||||
# Create a database user via SSL (MongoDB must be compiled with the SSL option and configured properly)
|
# Add 'mongo2.dev:30000' host into replica set as arbiter
|
||||||
- mongodb_user: database=burgers name=bob password=12345 state=present ssl=True
|
- mongodb_replication: replica_set=replSet host_name=mongo2.dev host_port=30000 host_type=arbiter state=present
|
||||||
|
|
||||||
# Delete 'burgers' database user with name 'bob'.
|
# Add 'mongo3.dev:27017' host into replica set as replica and authorization params
|
||||||
- mongodb_user: database=burgers name=bob state=absent
|
- mongodb_replication: replica_set=replSet login_host=mongo1.dev login_user=siteRootAdmin login_password=123456 host_name=mongo3.dev host_port=27017 state=present
|
||||||
|
|
||||||
# Define more users with various specific roles (if not defined, no roles is assigned, and the user will be added via pre mongo 2.2 style)
|
# Add 'mongo4.dev:27017' host into replica set as replica via SSL
|
||||||
- mongodb_user: database=burgers name=ben password=12345 roles='read' state=present
|
- mongodb_replication: replica_set=replSet host_name=mongo4.dev host_port=27017 ssl=True state=present
|
||||||
- mongodb_user: database=burgers name=jim password=12345 roles='readWrite,dbAdmin,userAdmin' state=present
|
|
||||||
- mongodb_user: database=burgers name=joe password=12345 roles='readWriteAnyDatabase' state=present
|
|
||||||
|
|
||||||
# add a user to database in a replica set, the primary server is automatically discovered and written to
|
# Remove 'mongo4.dev:27017' host from the replica set
|
||||||
- mongodb_user: database=burgers name=bob replica_set=blecher password=12345 roles='readWriteAnyDatabase' state=present
|
- mongodb_replication: replica_set=replSet host_name=mongo4.dev host_port=27017 state=absent
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
@ -278,6 +267,7 @@ def main():
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
config = { '_id': "{0}".format(replica_set), 'members': [{ '_id': 0, 'host': "{0}:{1}".format(host_name, host_port)}] }
|
config = { '_id': "{0}".format(replica_set), 'members': [{ '_id': 0, 'host': "{0}:{1}".format(host_name, host_port)}] }
|
||||||
client['admin'].command('replSetInitiate', config)
|
client['admin'].command('replSetInitiate', config)
|
||||||
|
time.sleep(3)
|
||||||
replica_set_created = True
|
replica_set_created = True
|
||||||
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
|
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
|
||||||
except OperationFailure, e:
|
except OperationFailure, e:
|
||||||
|
|
Loading…
Reference in New Issue