W3cubDocs

/Ansible

community.proxysql.proxysql_backend_servers – Adds or removes mysql hosts from proxysql admin interface

Note

This plugin is part of the community.proxysql collection (version 1.3.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.

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

Synopsis

Requirements

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

  • PyMySQL
  • mysqlclient

Parameters

Parameter Choices/Defaults Comments
comment
string
Default:
""
Text field that can be used for any purposed defined by the user. Could be a description of what the host stores, a reminder of when the host was added or disabled, or a JSON processed by some checker script.
compression
integer
If the value of compression is greater than 0, new connections to that server will use compression. If omitted the proxysql database default for compression is 0.
config_file
path
Default:
""
Specify a config file from which login_user and login_password are to be read.
hostgroup_id
integer
Default:
0
The hostgroup in which this mysqld instance is included. An instance can be part of one or more hostgroups.
hostname
string / required
The ip address at which the mysqld instance can be contacted.
load_to_runtime
boolean
    Choices:
  • no
  • yes
Dynamically load config to runtime memory.
login_host
string
Default:
"127.0.0.1"
The host used to connect to ProxySQL admin interface.
login_password
string
The password used to authenticate to ProxySQL admin interface.
login_port
integer
Default:
6032
The port used to connect to ProxySQL admin interface.
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_connections
integer
The maximum number of connections ProxySQL will open to this backend server. If omitted the proxysql database default for max_connections is 1000.
max_latency_ms
integer
Ping time is monitored regularly. If a host has a ping time greater than max_latency_ms it is excluded from the connection pool (although the server stays ONLINE). If omitted the proxysql database default for max_latency_ms is 0.
max_replication_lag
integer
If greater than 0, ProxySQL will regularly monitor replication lag. If replication lag goes above max_replication_lag, proxysql will temporarily shun the server until replication catches up. If omitted the proxysql database default for max_replication_lag is 0.
port
integer
Default:
3306
The port at which the mysqld instance can be contacted.
save_to_disk
boolean
    Choices:
  • no
  • yes
Save config to sqlite db on disk to persist the configuration.
state
string
    Choices:
  • present
  • absent
When present - adds the host, when absent - removes the host.
status
string
    Choices:
  • ONLINE
  • OFFLINE_SOFT
  • OFFLINE_HARD
ONLINE - Backend server is fully operational. OFFLINE_SOFT - When a server is put into OFFLINE_SOFT mode, connections are kept in use until the current transaction is completed. This allows to gracefully detach a backend. OFFLINE_HARD - When a server is put into OFFLINE_HARD mode, the existing connections are dropped, while new incoming connections aren't accepted either. If omitted the proxysql database default for status is ONLINE.
use_ssl
boolean
    Choices:
  • no
  • yes
If use_ssl is set to True, connections to this server will be made using SSL connections. If omitted the proxysql database default for use_ssl is False.
weight
integer
The bigger the weight of a server relative to other weights, the higher the probability of the server being chosen from the hostgroup. If omitted the proxysql database default for weight is 1.

Notes

Note

  • Supports check_mode.

Examples

---
# This example adds a server, it saves the mysql server config to disk, but
# avoids loading the mysql server config to runtime (this might be because
# several servers 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 server
  community.proxysql.proxysql_backend_servers:
    login_user: 'admin'
    login_password: 'admin'
    hostname: 'mysql01'
    state: present
    load_to_runtime: False

# This example removes a server, 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 server
  community.proxysql.proxysql_backend_servers:
    config_file: '~/proxysql.cnf'
    hostname: 'mysql02'
    state: absent

Return Values

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

Key Returned Description
stdout
dictionary
On create/update will return the newly modified host, on delete it will return the deleted record.
The mysql host modified or removed from proxysql

Sample:
{'changed': True, 'hostname': '192.168.52.1', 'msg': 'Added server to mysql_hosts', 'server': {'comment': '', 'compression': '0', 'hostgroup_id': '1', 'hostname': '192.168.52.1', 'max_connections': '1000', 'max_latency_ms': '0', 'max_replication_lag': '0', 'port': '3306', 'status': 'ONLINE', 'use_ssl': '0', 'weight': '1'}, 'state': 'present'}


Authors

  • Ben Mildren (@bmildren)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/proxysql/proxysql_backend_servers_module.html