mongodb_shard – Add and remove shards from a MongoDB Cluster

New in version 2.8.

Synopsis

  • Add and remove shards from a MongoDB Cluster.

Requirements

The below requirements are needed on the host that executes this module.

  • pymongo

Parameters

Parameter Choices/Defaults Comments
login_database
-
Default:
"admin"
The database where login credentials are stored.
login_host
-
Default:
"localhost"
The host to login to.
This must be a mongos.
login_password
-
The password used to authenticate with.
login_port
-
Default:
27017
The port to login to.
login_user
-
The user to login with.
shard
- / required
The shard connection string.
Should be supplied in the form <replicaset>/host:port as detailed in https://docs.mongodb.com/manual/tutorial/add-shards-to-shard-cluster/.
For example rs0/example1.mongodb.com:27017.
ssl
boolean
    Choices:
  • no ←
  • yes
Whether to use an SSL connection when connecting to the database.
ssl_cert_reqs
-
    Choices:
  • CERT_REQUIRED ←
  • CERT_OPTIONAL
  • CERT_NONE
Specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided.
state
-
    Choices:
  • present ←
  • absent
Whether the shard should be present or absent from the Cluster.

Notes

Note

Examples

# add a replicaset shard named rs1 with a member running on port 27018 on mongodb0.example.net
- mongodb_shard:
    login_user: admin
    login_password: admin
    shard: "rs1/mongodb0.example.net:27018"
    state: present

# add a standalone mongod shard running on port 27018 of mongodb0.example.net
- mongodb_shard:
    login_user: admin
    login_password: admin
    shard: "mongodb0.example.net:27018"
    state: present

# To remove a shard called 'rs1'
- mongodb_shard:
    login_user: admin
    login_password: admin
    shard: rs1
    state: absent

# Single node shard running on localhost
- name: Ensure shard rs0 exists
  mongodb_shard:
    login_user: admin
    login_password: secret
    shard: "rs0/localhost:3001"
    state: present

# Single node shard running on localhost
- name: Ensure shard rs1 exists
  mongodb_shard:
    login_user: admin
    login_password: secret
    shard: "rs1/localhost:3002"
    state: present

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
mongodb_shard
string
success
The name of the shard to create.



Status

Authors

  • Rhys Campbell (@rhysmeister)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.