community.proxysql.proxysql_mysql_hostgroup_attributes module – Manages hostgroup attributes using the ProxySQL admin interface

Note

This module is part of the community.proxysql collection (version 1.7.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.proxysql. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.proxysql.proxysql_mysql_hostgroup_attributes.

New in community.proxysql 1.7.0

Synopsis

  • Each row in mysql_hostgroup_attributes provides a per-hostgroup override of a specific hostgroup. This extension table allows for hostgroup-specific configurations, like `max_num_online_servers`, which change the behaviour of the given hostgroup in ways that are not otherwise possible.

Requirements

The below requirements are needed on the host that executes this module.

  • PyMySQL

  • mysqlclient

Parameters

Parameter

Comments

autocommit

integer

Not yet implemented (as per ProxySQL documentation).

Default: -1

comment

string

Text field that can be used for any purposes defined by the user.

Default: ""

config_file

path

Specify a config file from which login_user and login_password are to be read.

Default: ""

connection_warming

integer

Whether ProxySQL will opening new connections until the expected number of warm connections is reached

Default: 0

free_connections_pct

integer

The percentage of open idle connections for each server in a hostgroup.

Default: 10

hostgroup_id

integer / required

ID of the hostgroup

hostgroup_settings

string

Override certain global configurations.

Default: ""

ignore_session_variables

string

Not yet implemented (as per ProxySQL documentation).

Default: ""

init_connect

string

Semicolon-delimited string of SQL statements to be executed for each back-end connection when initialized.

Default: ""

load_to_runtime

boolean

Dynamically load config to runtime memory.

Choices:

  • false

  • true ← (default)

login_host

string

The host used to connect to ProxySQL admin interface.

Default: "127.0.0.1"

login_password

string

The password used to authenticate to ProxySQL admin interface.

login_port

integer

The port used to connect to ProxySQL admin interface.

Default: 6032

login_unix_socket

string

The socket used to connect to ProxySQL admin interface.

login_user

string

The username used to authenticate to ProxySQL admin interface.

max_num_online_servers

integer

Prevents new connections when the number of ONLINE servers in the hostgroup exceeds this number.

Default: 1000000

multiplex

integer

Enables or disables multiplexing for the specific hostgroup

Default: 1

save_to_disk

boolean

Save config to sqlite db on disk to persist the configuration.

Choices:

  • false

  • true ← (default)

servers_defaults

string

Provide default values for discovered servers.

Default: ""

state

string

When present - adds the hostgroup attributes, when absent - removes the hostgroup attributes.

Choices:

  • "present" ← (default)

  • "absent"

throttle_connections_per_sec

integer

Maximum number of new connections that can be opened per second.

Default: 1000000

Attributes

Attribute

Support

Description

check_mode

Support: full

Do not make any changes to memory, disk, or runtime.

Examples

# This example uses supplied credentials to add a hostgroup override for the
# hostgroup with ID, `1`. The override sets the maximum number of ONLINE
# servers to `1` and provides a short comment. The configuration will be saved
# to disk and memory, but not loaded into runtime.

- name: Add hostgroup overrides to limit servers
  community.proxysql.proxysql_mysql_hostgroup_overrides:
    login_user: admin
    login_password: admin
    hostgroup_id: 1
    state: present
    load_to_runtime: false
    max_num_online_servers: 1
    comment: >-
      Limit connections to the writer hostgroup to prevent split-brains.

# This example uses stored configuration to manage a hostgroup override for the
# hostgroup with ID, `2`. The override limits the number of new connections
# that can be opened to 100/sec. The configuration will be saved to memory and
# runtime but not persisted to disk.

- name: Throttle connections on reader hostgroup
  community.proxysql.proxysql_mysql_hostgroup_overrides:
    config_file: /etc/proxysql/admin.cnf
    hostgroup_id: 2
    state: present
    load_to_runtime: true
    save_to_disk: false
    throttle_connections_per_sec: 100

# This example uses supplied credentials to add a hostgroup override for the
# hostgroup with ID, `2`. The override enables multiplexing and sets the number
# of cached connections to 100%. The configuration will be saved to memory but
# not disk or runtime.

- name: Aggressively reuse and cache connections
  community.proxysql.proxysql_mysql_hostgroup_overrides:
    login_user: admin
    login_password: admin
    hostgroup_id: 2
    load_to_runtime: false
    save_to_disk: false
    multiplex: 1
    free_connections_pct: 100

# This example uses stored configuration to manage a hostgroup override for the
# hostgroup with ID, `42`. The override changes the hostgroup to handle
# warnings and each server added into the hostgroup to have 1000 connections.

- name: Override globals for hostgroup 42
  community.proxysql.proxysql_mysql_hostgroup_overrides:
    config_file: /etc/proxysql/admin.cnf
    hostgroup_id: 42
    hostgroup_settings: >-
      {
        "handle_warnings": 1
      }
    server_settings: >-
      {
        "max_connections": 1000
      }

# This example removes a hostgroup override using the credentials supplied in
# a configuration file.

- name: Remove hostgroup overrides
  community.proxysql.proxysql_mysql_hostgroup_attributes:
    config_file: '~/proxysql.cnf'
    hostgroup_id: 3
    state: absent

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

stdout

dictionary

The mysql_hostgroup_override modified or removed from ProxySQL.

Returned: On create/update will return the newly modified group, on delete it will return the deleted record.

Sample: {"changed": true, "msg": "Added server to mysql_hostgroup_overrides", "mysql_hostgroup_attributes": {"autocommit": "-1", "comment": "", "connection_warming": "0", "free_connections_pct": "10", "hostgroup_id": "21", "hostgroup_settings": "", "ignore_session_variables": "", "init_connect": "", "max_num_online_servers": "1000000", "multiplex": "1", "servers_defaults": "", "throttle_connections_per_sec": "1000000"}, "state": "present"}

Authors

  • Richard Burnison (@burnison)