community / community.general / 0.1.1 / module / mysql_replication Manage MySQL replication Authors: Balazs Pocze (@banyek), Andrew Klychkov (@Andersson007) preview | supported by communitycommunity.general.mysql_replication (0.1.1) — module
Install with ansible-galaxy collection install community.general:==0.1.1
collections: - name: community.general version: 0.1.1
Manages MySQL server replication, slave, master status, get and change master host.
- name: Stop mysql slave thread mysql_replication: mode: stopslave
- name: Get master binlog file name and binlog position mysql_replication: mode: getmaster
- name: Change master to master server 192.0.2.1 and use binary log 'mysql-bin.000009' with position 4578 mysql_replication: mode: changemaster master_host: 192.0.2.1 master_log_file: mysql-bin.000009 master_log_pos: 4578
- name: Check slave status using port 3308 mysql_replication: mode: getslave login_host: ansible.example.com login_port: 3308
- name: On MariaDB change master to use GTID current_pos mysql_replication: mode: changemaster master_use_gtid: current_pos
- name: Change master to use replication delay 3600 seconds mysql_replication: mode: changemaster master_host: 192.0.2.1 master_delay: 3600
- name: Start MariaDB standby with connection name master-1 mysql_replication: mode: startslave connection_name: master-1
- name: Stop replication in channel master-1 mysql_replication: mode: stopslave channel: master-1
- name: > Run RESET MASTER command which will delete all existing binary log files and reset the binary log index file on the master mysql_replication: mode: resetmaster
- name: Run start slave and fail the task on errors mysql_replication: mode: startslave connection_name: master-1 fail_on_error: yes
- name: Change master and fail on error (like when slave thread is running) mysql_replication: mode: changemaster fail_on_error: yes
mode: choices: - changemaster - getmaster - getslave - startslave - stopslave - resetmaster - resetslave - resetslaveall default: getslave description: - Module operating mode. Could be C(changemaster) (CHANGE MASTER TO), C(getmaster) (SHOW MASTER STATUS), C(getslave) (SHOW SLAVE STATUS), C(startslave) (START SLAVE), C(stopslave) (STOP SLAVE), C(resetmaster) (RESET MASTER) - supported from Ansible 2.10, C(resetslave) (RESET SLAVE), C(resetslaveall) (RESET SLAVE ALL). type: str ca_cert: aliases: - ssl_ca description: - The path to a Certificate Authority (CA) certificate. This option, if used, must specify the same certificate as used by the server. type: path channel: description: - Name of replication channel. - Multi-source replication is supported from MySQL 5.7. - Mutually exclusive with I(connection_name). - For more information see U(https://dev.mysql.com/doc/refman/8.0/en/replication-multi-source.html). type: str client_key: aliases: - ssl_key description: - The path to the client private key. type: path login_host: default: localhost description: - Host running the database. - In some cases for local connections the I(login_unix_socket=/path/to/mysqld/socket), that is usually C(/var/run/mysqld/mysqld.sock), needs to be used instead of I(login_host=localhost). type: str login_port: default: 3306 description: - Port of the MySQL server. Requires I(login_host) be defined as other than localhost if login_port is used. type: int login_user: description: - The username used to authenticate with. type: str master_ssl: description: - Same as mysql variable. type: bool client_cert: aliases: - ssl_cert description: - The path to a client public key certificate. type: path config_file: default: ~/.my.cnf description: - Specify a config file from which user and password are to be read. type: path master_host: description: - Same as mysql variable. type: str master_port: description: - Same as mysql variable. type: int master_user: description: - Same as mysql variable. type: str master_delay: description: - Time lag behind the master's state (in seconds). - Available from MySQL 5.6. - For more information see U(https://dev.mysql.com/doc/refman/8.0/en/replication-delayed.html). type: int fail_on_error: default: false description: - Fails on error when calling mysql. type: bool master_ssl_ca: description: - Same as mysql variable. type: str relay_log_pos: description: - Same as mysql variable. type: int login_password: description: - The password used to authenticate with. type: str master_log_pos: description: - Same as mysql variable. type: int master_ssl_key: description: - Same as mysql variable. type: str relay_log_file: description: - Same as mysql variable. type: str connect_timeout: default: 30 description: - The connection timeout when connecting to the MySQL server. type: int connection_name: description: - Name of the master connection. - Supported from MariaDB 10.0.1. - Mutually exclusive with I(channel). - For more information see U(https://mariadb.com/kb/en/library/multi-source-replication/). type: str master_log_file: description: - Same as mysql variable. type: str master_password: description: - Same as mysql variable. type: str master_ssl_cert: description: - Same as mysql variable. type: str master_use_gtid: choices: - current_pos - slave_pos - disabled description: - Configures the slave to use the MariaDB Global Transaction ID. - C(disabled) equals MASTER_USE_GTID=no command. - To find information about available values see U(https://mariadb.com/kb/en/library/change-master-to/#master_use_gtid). - Available since MariaDB 10.0.2. type: str login_unix_socket: description: - The path to a Unix domain socket for local connections. type: str master_ssl_capath: description: - Same as mysql variable. type: str master_ssl_cipher: description: - Same as mysql variable. type: str master_auto_position: description: - Whether the host uses GTID based replication or not. type: bool master_connect_retry: description: - Same as mysql variable. type: int
queries: description: List of executed queries which modified DB's state. returned: always sample: - CHANGE MASTER TO MASTER_HOST='master2.example.com',MASTER_PORT=3306 type: list version_added: '2.10' version_added_collection: community.general