community.mongodb.mongodb_status (1.7.3) — module

Validates the status of the replicaset.

| "added in version" 1.0.0 of community.mongodb"

Authors: Rhys Campbell (@rhysmeister)

Install collection

Install with ansible-galaxy collection install community.mongodb:==1.7.3


Add to requirements.yml

  collections:
    - name: community.mongodb
      version: 1.7.3

Description

Validates the status of the replicaset.

The module expects all replicaset nodes to be PRIMARY, SECONDARY or ARBITER.

Will wait until a timeout for the replicaset state to converge if required.

Can also be used to lookup the current PRIMARY member (see examples).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Check replicaset is healthy, fail if not after first attempt
  community.mongodb.mongodb_status:
    replica_set: rs0
  when: ansible_hostname == "mongodb1"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Wait for the replicaset rs0 to converge, check 5 times, 10 second interval between checks
  community.mongodb.mongodb_status:
    replica_set: rs0
    poll: 5
    interval: 10
  when: ansible_hostname == "mongodb1"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Get the replicaset status and then lookup the primary's hostname and save to a variable
- name: Ensure replicaset is stable before beginning
  community.mongodb.mongodb_status:
    login_user: "{{ admin_user }}"
    login_password: "{{ admin_user_password }}"
    poll: 3
    interval: 10
  register: rs
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Lookup PRIMARY replicaset member
  set_fact:
    primary: "{{ item.key.split('.')[0] }}"
  loop: "{{ lookup('dict', rs.replicaset) }}"
  when: "'PRIMARY' in item.value"

Inputs

    
ssl:
    aliases:
    - tls
    default: false
    description:
    - Whether to use an SSL connection when connecting to the database.
    required: false
    type: bool

poll:
    default: 1
    description:
    - The maximum number of times to query for the replicaset status before the set converges
      or we fail.
    type: int

interval:
    default: 30
    description:
    - The number of seconds to wait between polling executions.
    type: int

validate:
    choices:
    - default
    - votes
    - minimal
    default: default
    description:
    - The type of validate to perform on the replicaset.
    - default, Suitable for most purposes. Validate that there are an odd number of servers
      and one is PRIMARY and the remainder are in a SECONDARY or ARBITER state.
    - votes, Check the number of votes is odd and one is a PRIMARY and the remainder are
      in a SECONDARY or ARBITER state. Authentication is required here to get the replicaset
      configuration.
    - minimal, Just checks that one server is in a PRIMARY state with the remainder being
      SECONDARY or ARBITER.
    type: str

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

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

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

Outputs

failed:
  description: If the module has failed or not.
  returned: always
  type: bool
iterations:
  description: Number of times the module has queried the replicaset status.
  returned: always
  type: int
msg:
  description: Status message.
  returned: always
  type: str
replicaset:
  description: The last queried status of all the members of the replicaset if obtainable.
  returned: always
  type: dict