mongodb_shard -- Add or remove shards from a MongoDB Cluster

Synopsis

Add or remove shards from a MongoDB Cluster.

Requirements

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

Parameters

shard (True, str, None)

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.

sharded_databases (False, raw, None)

Enable sharding on the listed database.

Can be supplied as a string or a list of strings.

Sharding cannot be disabled on a database.

mongos_process (False, str, mongos)

Provide a custom name for the mongos process you are connecting to.

Most users can ignore this setting.

state (False, str, present)
Whether the shard should be present or absent from the Cluster.
login_user (False, str, None)

The MongoDB user to login with.

Required when login_password is specified.

login_password (False, str, None)

The password used to authenticate with.

Required when login_user is specified.

login_database (False, str, admin)
The database where login credentials are stored.
login_host (False, str, localhost)
The host running MongoDB instance to login to.
login_port (False, int, 27017)
The MongoDB server port to login to.
strict_compatibility (optional, bool, True)
Enforce strict requirements for pymongo and MongoDB software versions
ssl (False, bool, False)
Whether to use an SSL connection when connecting to the database.
ssl_cert_reqs (False, str, CERT_REQUIRED)
Specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided.
ssl_ca_certs (False, str, None)
The ssl_ca_certs option takes a path to a CA file.
ssl_crlfile (False, str, None)
The ssl_crlfile option takes a path to a CRL file.
ssl_certfile (False, str, None)
Present a client certificate using the ssl_certfile option.
ssl_keyfile (False, str, None)
Private key for the client certificate.
ssl_pem_passphrase (False, str, None)
Passphrase to decrypt encrypted private keys.
auth_mechanism (False, str, None)
Authentication type.
connection_options (False, list, None)

Additional connection options.

Supply as a list of dicts or strings containing key value pairs seperated with '='.

Notes

Note

  • Requires the pymongo Python package on the remote host, version 2.4.2+.

Examples

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

- name: Add a standalone mongod shard running on port 27018 of mongodb0.example.net
  community.mongodb.mongodb_shard:
    login_user: admin
    login_password: admin
    shard: "mongodb0.example.net:27018"
    state: present

- name: To remove a shard called 'rs1'
  community.mongodb.mongodb_shard:
    login_user: admin
    login_password: admin
    shard: rs1
    state: absent

# Single node shard running on localhost
- name: Ensure shard rs0 exists
  community.mongodb.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
  community.mongodb.mongodb_shard:
    login_user: admin
    login_password: secret
    shard: "rs1/localhost:3002"
    state: present

# Enable sharding on a few databases when creating the shard
- name: To remove a shard called 'rs1'
  community.mongodb.mongodb_shard:
    login_user: admin
    login_password: admin
    shard: rs1
    sharded_databases:
      - db1
      - db2
    state: present

Return Values

mongodb_shard (success, str, )
The name of the shard to create.
sharded_enabled (success when sharding is enabled, list, )
Databases that have had sharding enabled during module execution.

Status

Authors

  • Rhys Campbell (@rhysmeister)