mongodb_replicaset – Initialises a MongoDB replicaset¶
New in version 2.8.
Synopsis¶
Initialises a MongoDB replicaset in a new deployment.
Validates the replicaset name for existing deployments.
Requirements¶
The below requirements are needed on the host that executes this module.
pymongo
Parameters¶
Parameter | Choices/Defaults | Comments |
---|---|---|
arbiter_at_index
integer
|
Identifies the position of the member in the array that is an arbiter.
|
|
chaining_allowed
boolean
|
|
When settings.chaining_allowed=true, the replicaset allows secondary members to replicate from other secondary members.
When settings.chaining_allowed=false, secondaries can replicate only from the primary.
|
election_timeout_millis
integer
|
Default: 10000
|
The time limit in milliseconds for detecting when a replicaset's primary is unreachable.
|
heartbeat_timeout_secs
integer
|
Default: 10
|
Number of seconds that the replicaset members wait for a successful heartbeat from each other.
If a member does not respond in time, other members mark the delinquent member as inaccessible.
The setting only applies when using protocol_version=0. When using protocol_version=1 the relevant setting is settings.election_timeout_millis.
|
login_database
string
|
Default: "admin"
|
The database where login credentials are stored.
|
login_host
string
|
Default: "localhost"
|
The MongoDB hostname.
|
login_password
string
|
The password to authenticate with.
|
|
login_port
integer
|
Default: 27017
|
The MongoDB port to login to.
|
login_user
string
|
The username to authenticate with.
|
|
members
list
|
A comma-separated string or a yaml list consisting of the replicaset members.
Supply as a simple csv string, i.e. mongodb1:27017,mongodb2:27017,mongodb3:27017.
If a port number is not provided then 27017 is assumed.
|
|
protocol_version
integer
|
|
Version of the replicaset election protocol.
|
replica_set
string
|
Default: "rs0"
|
Replicaset name.
|
ssl
boolean
|
|
Whether to use an SSL connection when connecting to the database
|
ssl_cert_reqs
string
|
|
Specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided.
|
validate
boolean
|
|
Performs some basic validation on the provided replicaset config.
|
Notes¶
Note
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
Examples¶
# Create a replicaset called 'rs0' with the 3 provided members
- name: Ensure replicaset rs0 exists
mongodb_replicaset:
login_host: localhost
login_user: admin
login_password: admin
replica_set: rs0
members:
- mongodb1:27017
- mongodb2:27017
- mongodb3:27017
when: groups.mongod.index(inventory_hostname) == 0
# Create two single-node replicasets on the localhost for testing
- name: Ensure replicaset rs0 exists
mongodb_replicaset:
login_host: localhost
login_port: 3001
login_user: admin
login_password: secret
login_database: admin
replica_set: rs0
members: localhost:3001
validate: no
- name: Ensure replicaset rs1 exists
mongodb_replicaset:
login_host: localhost
login_port: 3002
login_user: admin
login_password: secret
login_database: admin
replica_set: rs1
members: localhost:3002
validate: no
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description |
---|---|---|
mongodb_replicaset
string
|
success |
The name of the replicaset that has been created.
|
Status¶
This module is not guaranteed to have a backwards compatible interface. [preview]
This module is maintained by the Ansible Community. [community]