community.mongodb.mongodb_balancer 模块 – 管理 MongoDB 分片集群平衡器。

注意

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

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

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

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

community.mongodb 1.0.0 中的新增功能

概要

  • 管理 MongoDB 分片集群平衡器。

  • 启动或停止平衡器。

  • 调整集群块大小。

  • 启用或禁用自动分割。

  • 添加或删除平衡器窗口。

要求

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

  • pymongo

参数

参数

注释

atlas_auth

布尔值

用于 MongoDB Atlas 实例的身份验证路径

选择

  • false ← (默认)

  • true

auth_mechanism

字符串

身份验证类型。

选择

  • "SCRAM-SHA-256"

  • "SCRAM-SHA-1"

  • "MONGODB-X509"

  • "GSSAPI"

  • "PLAIN"

autosplit

布尔值

禁用或启用 config.settings 集合中的 autosplit 标志。

从 MongoDB 6.1 开始,不会执行自动块拆分,因此此参数在当前版本和更高版本中无效。有关更多信息,请参阅 [enableAutoSplit](https://mongodb.ac.cn/docs/manual/reference/method/sh.enableAutoSplit/)。

此参数已弃用,将在未来版本中删除。

选择

  • false

  • true

chunksize

整数

控制分片集群中块的大小。

值应以 MB 为单位给出。

connection_options

列表 / elements=any

其他连接选项。

以字典列表或包含用“=”分隔的键值对的字符串形式提供。

login_database

字符串

存储登录凭据的数据库。

默认值: "admin"

login_host

字符串

运行要登录的 MongoDB 实例的主机。

默认值: "localhost"

login_password

字符串

用于身份验证的密码。

当指定 login_user 时是必需的。

login_port

整数

要登录的 MongoDB 服务器端口。

默认值: 27017

login_user

字符串

用于登录的 MongoDB 用户。

当指定 login_password 时是必需的。

mongos_process

字符串

为 mongos 进程提供自定义名称。

大多数用户可以忽略此设置。

默认值: "mongos"

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

字符串

管理集群的平衡器

选择

  • "started" ← (默认)

  • "stopped"

strict_compatibility

布尔值

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

选择

  • false

  • true ← (默认)

window

任何

安排平衡器窗口。

提供以下字典键 start、stop、state

state 键应为“present”或“absent”。

当 state 为“absent”时,start 和 stop 键将被忽略。

start 和 stop 应为“HH:MM”格式的字符串,表示窗口的时间界限。

注意

注意

示例

- name: Start the balancer
  community.mongodb.mongodb_balancer:
    state: started

- name: Stop the balancer and disable autosplit
  community.mongodb.mongodb_balancer:
    state: stopped
    autosplit: false

- name: Enable autosplit
  community.mongodb.mongodb_balancer:
    autosplit: true

- name: Change the default chunksize to 128MB
  community.mongodb.mongodb_balancer:
    chunksize: 128

- name: Add or update a balancing window
  community.mongodb.mongodb_balancer:
    window:
      start: "23:00"
      stop: "06:00"
      state: "present"

- name: Remove a balancing window
  community.mongodb.mongodb_balancer:
    window:
      state: "absent"

返回值

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

描述

changed

布尔值

均衡器状态或自动分割是否已更改。

返回:成功

failed

布尔值

如果发生错误

返回:失败

msg

字符串

对发生的事情的简短描述。

返回:失败

new_autosplit

字符串

自动分割的新状态。

返回:当自动分割更改时。

new_balancer_state

字符串

均衡器的新状态。

返回:当均衡器状态更改时

new_chunksize

整数

块大小的新值。

返回:当块大小更改时。

old_autosplit

字符串

自动分割的先前状态。

返回:当自动分割更改时。

old_balancer_state

字符串

均衡器的先前状态

返回:当均衡器状态更改时

old_chunksize

整数

块大小的先前值。

返回:当块大小更改时。

作者

  • Rhys Campbell (@rhysmeister)