community.mongodb.mongodb_schema (1.7.3) — module

Manages MongoDB Document Schema Validators.

| "added in version" 1.3.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

Manages MongoDB Document Schema Validators.

Create, update and remove Validators on a collection.

Supports the entire range of jsonSchema keywords.

See [jsonSchema Available Keywords](https://docs.mongodb.com/manual/reference/operator/query/jsonSchema/#available-keywords) for details.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
---
- name: Require that an email address field is in every document
  community.mongodb.mongodb_schema:
    collection: contacts
    db: rhys
    required:
      - email
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove a schema rule
  community.mongodb.mongodb_schema:
    collection: contacts
    db: rhys
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- name: More advanced example using properties
  community.mongodb.mongodb_schema:
    collection: contacts
    db: rhys
    properties:
      email:
        maxLength: 150
        minLength: 5
      options:
        bsonType: array
        maxItems: 10
        minItems: 5
        uniqueItems: true
      status:
        bsonType: string
        description: "can only be ACTIVE or DISABLED"
        enum:
          - ACTIVE
          - DISABLED
      year:
        bsonType: int
        description: "must be an integer from 2021 to 3020"
        exclusiveMaximum: false
        maximum: 3020
        minimum: 2021
    required:
      - email
      - first_name
      - last_name

Inputs

    
db:
    description:
    - The database to work with.
    required: true
    type: str

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:
    - Enable additional debugging output.
    type: bool

level:
    choices:
    - strict
    - moderate
    default: strict
    description:
    - The validation level MongoDB should apply when updating existing documents.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - The state of the validator.
    type: str

action:
    choices:
    - error
    - warn
    default: error
    description:
    - The validation action for MongoDB to perform when handling invalid documents.
    type: str

required:
    description:
    - List of fields that are required.
    elements: str
    type: list

atlas_auth:
    default: false
    description:
    - Authentication path intended for MongoDB Atlas Instances
    type: bool

collection:
    description:
    - The collection to work with.
    required: true
    type: str

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

properties:
    default: {}
    description:
    - Individual property specification.
    type: dict

replica_set:
    default: null
    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

changed:
  description: If the module caused a change.
  returned: on success
  type: bool
module_config:
  description: The validator document as indicated by the module invocation.
  returned: when debug is true
  type: dict
msg:
  description: Status message.
  returned: always
  type: str
validator:
  description: The validator document as read from the instance.
  returned: when debug is true
  type: dict