community.proxysql.proxysql_replication_hostgroups 模块 – 使用 proxysql 管理界面管理复制主机组

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.proxysql。您需要其他要求才能使用此模块,请参阅 需求了解详情。

要在剧本中使用它,请指定:community.proxysql.proxysql_replication_hostgroups

概要

  • mysql_replication_hostgroups 中的每一行代表一对 writer_hostgroup 和 reader_hostgroup。ProxySQL 将监控指定主机组中所有服务器的 read_only 值,并根据 read_only 值将服务器分配给 writer 或 reader 主机组。

需求

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

  • PyMySQL

  • mysqlclient

参数

参数

注释

check_type

字符串

在 community.proxysql 1.3.0 中添加

检测节点是否为备用节点时使用的检查类型。

需要 proxysql >= 2.0.1。否则无效。

read_only|innodb_read_onlyread_only&innodb_read_only 需要 proxysql >= 2.0.8。

选项

  • "read_only" ← (默认)

  • "innodb_read_only"

  • "super_read_only"

  • "read_only|innodb_read_only"

  • "read_only&innodb_read_only"

comment

字符串

可用于用户定义的任何用途的文本字段。

默认值: ""

config_file

路径

指定一个配置文件,从中读取login_userlogin_password

默认值: ""

load_to_runtime

布尔值

动态地将配置加载到运行时内存。

选项

  • false

  • true ← (默认)

login_host

字符串

用于连接到 ProxySQL 管理界面的主机。

默认值: "127.0.0.1"

login_password

字符串

用于对 ProxySQL 管理界面进行身份验证的密码。

login_port

整数

用于连接到 ProxySQL 管理界面的端口。

默认值: 6032

login_unix_socket

字符串

用于连接到 ProxySQL 管理界面的套接字。

login_user

字符串

用于对 ProxySQL 管理界面进行身份验证的用户名。

reader_hostgroup

整数 / 必填

读取器主机组的 ID。

save_to_disk

布尔值

将配置保存到磁盘上的 sqlite 数据库以持久化配置。

选项

  • false

  • true ← (默认)

state

字符串

present 时 - 添加复制主机组,当 absent 时 - 删除复制主机组。

选项

  • "present" ← (默认)

  • "absent"

writer_hostgroup

整数 / 必填

写入器主机组的 ID。

注释

注意

  • 支持 check_mode

示例

---
# This example adds a replication hostgroup, it saves the mysql server config
# to disk, but avoids loading the mysql server config to runtime (this might be
# because several replication hostgroup are being added and the user wants to
# push the config to runtime in a single batch using the
# community.general.proxysql_manage_config module).  It uses supplied credentials
# to connect to the proxysql admin interface.

- name: Add a replication hostgroup
  community.proxysql.proxysql_replication_hostgroups:
    login_user: 'admin'
    login_password: 'admin'
    writer_hostgroup: 1
    reader_hostgroup: 2
    state: present
    load_to_runtime: false

- name: Change check_type
  community.proxysql.proxysql_replication_hostgroups:
    login_user: 'admin'
    login_password: 'admin'
    writer_hostgroup: 1
    reader_hostgroup: 2
    check_type: innodb_read_only
    state: present
    load_to_runtime: false

# This example removes a replication hostgroup, saves the mysql server config
# to disk, and dynamically loads the mysql server config to runtime.  It uses
# credentials in a supplied config file to connect to the proxysql admin
# interface.

- name: Remove a replication hostgroup
  community.proxysql.proxysql_replication_hostgroups:
    config_file: '~/proxysql.cnf'
    writer_hostgroup: 3
    reader_hostgroup: 4
    state: absent

返回值

常用的返回值在此处有说明 此处,以下是此模块特有的字段

描述

stdout

字典

从 proxysql 中修改或删除的复制主机组。

返回: 创建/更新时将返回新修改的组,删除时将返回已删除的记录。

示例: {"changed": true, "msg": "Added server to mysql_hosts", "repl_group": {"check_type": "read_only", "comment": "", "reader_hostgroup": "1", "writer_hostgroup": "2"}, "state": "present"}

作者

  • Ben Mildren (@bmildren)