community / community.mongodb / 1.7.3 / module / mongodb_replicaset Initialises a MongoDB replicaset. | "added in version" 1.0.0 of community.mongodb" Authors: Rhys Campbell (@rhysmeister)community.mongodb.mongodb_replicaset (1.7.3) — module
Install with ansible-galaxy collection install community.mongodb:==1.7.3
collections: - name: community.mongodb version: 1.7.3
Initialises a MongoDB replicaset in a new deployment.
Validates the replicaset name for existing deployments.
Advanced replicaset member (re)configuration possible (see examples).
Initialize the replicaset before adding users as per \ [best practice](https://www.mongodb.com/docs/manual/tutorial/deploy-replica-set-with-keyfile-access-control/).
# Create a replicaset called 'rs0' with the 3 provided members - name: Ensure replicaset rs0 exists community.mongodb.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 community.mongodb.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 community.mongodb.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
- name: Create a replicaset and use a custom priority for each member community.mongodb.mongodb_replicaset: login_host: localhost login_user: admin login_password: admin replica_set: rs0 members: - host: "localhost:3001" priority: 1 - host: "localhost:3002" priority: 0.5 - host: "localhost:3003" priority: 0.5 when: groups.mongod.index(inventory_hostname) == 0
- name: Create replicaset rs1 with options and member tags community.mongodb.mongodb_replicaset: login_host: localhost login_port: 3001 login_database: admin replica_set: rs1 members: - host: "localhost:3001" priority: 1 tags: dc: "east" usage: "production" - host: "localhost:3002" priority: 1 tags: dc: "east" usage: "production" - host: "localhost:3003" priority: 0 hidden: true slaveDelay: 3600 tags: dc: "west" usage: "reporting"
- name: Replicaset with one arbiter node (mongodb3 - index is zero-based) community.mongodb.mongodb_replicaset: login_user: admin login_password: admin replica_set: rs0 members: - mongodb1:27017 - mongodb2:27017 - mongodb3:27017 arbiter_at_index: 2 when: groups.mongod.index(inventory_hostname) == 0
- name: Add a new member to a replicaset - Safe for pre-5.0 consult documentation - https://docs.mongodb.com/manual/tutorial/expand-replica-set/ block: - name: Create replicaset with module - with dicts community.mongodb.mongodb_replicaset: replica_set: "rs0" members: - host: localhost:3001 - host: localhost:3002 - host: localhost:3003 - name: Wait for the replicaset to stabilise community.mongodb.mongodb_status: replica_set: "rs0" poll: 5 interval: 10 - name: Remove a member from the replicaset community.mongodb.mongodb_replicaset: replica_set: "rs0" reconfigure: yes members: - host: localhost:3001 - host: localhost:3002 - name: Wait for the replicaset to stabilise after member removal community.mongodb.mongodb_status: replica_set: "rs0" validate: minimal poll: 5 interval: 10 - name: Add a member to the replicaset community.mongodb.mongodb_replicaset: replica_set: "rs0" reconfigure: yes members: - host: localhost:3001 - host: localhost:3002 - host: localhost:3004 hidden: true votes: 0 priority: 0 - name: Wait for the replicaset to stabilise after member addition community.mongodb.mongodb_status: replica_set: "rs0" validate: minimal poll: 5 interval: 30 - name: Reconfigure the replicaset - Make member 3004 a normal voting member community.mongodb.mongodb_replicaset: replica_set: "rs0" reconfigure: yes members: - host: localhost:3001 - host: localhost:3002 - host: localhost:3004 hidden: false votes: 1 priority: 1 - name: Wait for the replicaset to stabilise community.mongodb.mongodb_status: replica_set: "rs0" poll: 5 interval: 30
ssl: aliases: - tls default: false description: - Whether to use an SSL connection when connecting to the database. required: false type: bool debug: default: false description: - Add additonal info for debug. type: bool force: default: false description: - Only relevant when reconfigure = true. - Specify true to force the available replica set members to accept the new configuration. - Force reconfiguration can result in unexpected or undesired behavior, including rollback of "majority" committed writes. type: bool members: description: - Yaml list consisting of the replicaset members. - Csv string will also be accepted i.e. mongodb1:27017,mongodb2:27017,mongodb3:27017. - A dictionary can also be used to specify advanced replicaset member options. - If a port number is not provided then 27017 is assumed. elements: raw type: list validate: default: true description: - Performs some basic validation on the provided replicaset config. type: bool atlas_auth: default: false description: - Authentication path intended for MongoDB Atlas Instances type: bool login_host: default: localhost description: - The host running MongoDB instance to login to. required: false type: str login_port: default: 27017 description: - The MongoDB server port to login to. required: false type: int login_user: description: - The MongoDB user to login with. - Required when I(login_password) is specified. required: false type: str cluster_cmd: choices: - isMaster - hello default: hello description: - Command the module should use to obtain information about the MongoDB node we are connecting to. type: str max_time_ms: default: null description: - Specifies a cumulative time limit in milliseconds for processing the replicaset reconfiguration. type: int reconfigure: default: false description: - This feature is currently experimental. Please test your scenario thoroughly. - Consult the integration test file for supported scenarios - \ [Integration tests](https://github.com/ansible-collections/community.mongodb/tree/master/tests/integration/targets/mongodb_replicaset/tasks). \ See files prefixed with 330. - Whether to perform replicaset reconfiguration actions. - Only relevant when the replicaset already exists. - Only one member should be removed or added per invocation. - Members should be specific as either all strings or all dicts when reconfiguring. - Currently no support for replicaset settings document changes. type: bool replica_set: default: rs0 description: - Replicaset name. type: str ssl_crlfile: description: - The ssl_crlfile option takes a path to a CRL file. required: false type: str ssl_keyfile: description: - Private key for the client certificate. required: false type: str ssl_ca_certs: aliases: - tlsCAFile description: - The ssl_ca_certs option takes a path to a CA file. required: false type: str ssl_certfile: aliases: - tlsCertificateKeyFile description: - Present a client certificate using the ssl_certfile option. required: false type: str ssl_cert_reqs: aliases: - tlsAllowInvalidCertificates choices: - CERT_NONE - CERT_OPTIONAL - CERT_REQUIRED default: CERT_REQUIRED description: - Specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided. required: false type: str auth_mechanism: choices: - SCRAM-SHA-256 - SCRAM-SHA-1 - MONGODB-X509 - GSSAPI - PLAIN description: - Authentication type. required: false type: str login_database: default: admin description: - The database where login credentials are stored. required: false type: str login_password: description: - The password used to authenticate with. - Required when I(login_user) is specified. required: false type: str arbiter_at_index: description: - Identifies the position of the member in the array that is an arbiter. type: int chaining_allowed: default: true description: - When I(settings.chaining_allowed=true), the replicaset allows secondary members to replicate from other secondary members. - When I(settings.chaining_allowed=false), secondaries can replicate only from the primary. type: bool protocol_version: choices: - 0 - 1 default: 1 description: Version of the replicaset election protocol. type: int connection_options: description: - Additional connection options. - Supply as a list of dicts or strings containing key value pairs seperated with '='. elements: raw required: false type: list ssl_pem_passphrase: aliases: - tlsCertificateKeyFilePassword description: - Passphrase to decrypt encrypted private keys. required: false type: str strict_compatibility: default: true description: - Enforce strict requirements for pymongo and MongoDB software versions type: bool heartbeat_timeout_secs: default: 10 description: - 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 I(protocol_version=0). When using I(protocol_version=1) the relevant setting is I(settings.election_timeout_millis). type: int election_timeout_millis: default: 10000 description: - The time limit in milliseconds for detecting when a replicaset's primary is unreachable. type: int
mongodb_replicaset: description: The name of the replicaset that has been created. returned: success type: str reconfigure: description: If a replicaset reconfiguration occured. returned: On rpelicaset reconfiguration type: bool