community.mongodb.mongodb_schema 模块 – 管理 MongoDB 文档模式验证器。

注意

此模块是 community.mongodb 集合 (版本 1.7.8) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.mongodb。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求

要在 playbook 中使用它,请指定:community.mongodb.mongodb_schema

community.mongodb 1.3.0 中的新增功能

概要

要求

在执行此模块的主机上需要以下要求。

  • pymongo

参数

参数

注释

action

字符串

MongoDB 在处理无效文档时要执行的验证操作。

选项

  • "error" ← (默认)

  • "warn"

atlas_auth

布尔值

适用于 MongoDB Atlas 实例的认证路径

选项

  • false ← (默认)

  • true

auth_mechanism

字符串

身份验证类型。

选项

  • "SCRAM-SHA-256"

  • "SCRAM-SHA-1"

  • "MONGODB-X509"

  • "GSSAPI"

  • "PLAIN"

collection

字符串 / 必需

要使用的集合。

connection_options

列表 / 元素=任意

附加连接选项。

以字典或字符串列表的形式提供,键值对用 ‘=’ 分隔。

db

字符串 / 必需

要使用的数据库。

debug

布尔值

启用额外的调试输出。

选项

  • false ← (默认)

  • true

level

字符串

更新现有文档时 MongoDB 应应用的验证级别。

选项

  • "strict" ← (默认)

  • "moderate"

login_database

字符串

存储登录凭据的数据库。

默认值: "admin"

login_host

字符串

要登录的 MongoDB 实例的主机。

默认值: "localhost"

login_password

字符串

用于身份验证的密码。

当指定 login_user 时必需。

login_port

整数

要登录的 MongoDB 服务器端口。

默认值: 27017

login_user

字符串

要登录的 MongoDB 用户。

当指定 login_password 时必需。

properties

字典

单个属性规范。

默认值: {}

replica_set

字符串

副本集名称。

required

列表 / 元素=字符串

必需字段的列表。

ssl

别名:tls

布尔值

连接到数据库时是否使用 SSL 连接。

选项

  • false ← (默认)

  • true

ssl_ca_certs

别名:tlsCAFile

字符串

ssl_ca_certs 选项接受 CA 文件的路径。

ssl_cert_reqs

别名:tlsAllowInvalidCertificates

字符串

指定是否需要连接另一端提供证书,以及如果提供是否验证证书。

选项

  • "CERT_NONE"

  • "CERT_OPTIONAL"

  • "CERT_REQUIRED" ← (默认)

ssl_certfile

别名:tlsCertificateKeyFile

字符串

使用 ssl_certfile 选项出示客户端证书。

ssl_crlfile

字符串

ssl_crlfile 选项指定 CRL 文件的路径。

ssl_keyfile

字符串

客户端证书的私钥。

ssl_pem_passphrase

别名:tlsCertificateKeyFilePassword

字符串

解密加密私钥的密码。

state

字符串

验证器的状态。

选项

  • "present" ← (默认)

  • "absent"

strict_compatibility

布尔值

强制执行 pymongo 和 MongoDB 软件版本的严格要求

选项

  • false

  • true ← (默认)

注释

注意

  • 需要远程主机上安装 pymongo Python 包,版本 4+。

示例

---
- name: Require that an email address field is in every document
  community.mongodb.mongodb_schema:
    collection: contacts
    db: rhys
    required:
      - email

- name: Remove a schema rule
  community.mongodb.mongodb_schema:
    collection: contacts
    db: rhys
    state: absent


- 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

返回值

常见的返回值已在 此处 记录,以下是此模块特有的字段

描述

changed

布尔值

如果模块导致更改。

返回:成功时

module_config

字典

模块调用指示的验证器文档。

返回:当 debug 为 true 时

msg

字符串

状态消息。

返回:始终

validator

字典

从实例读取的验证器文档。

返回:当 debug 为 true 时

作者

  • Rhys Campbell (@rhysmeister)