From 47610347baa5a23a65f0d3221382a09ee964f0e1 Mon Sep 17 00:00:00 2001 From: Dennis Felipe Urtubia <33161939+dennisurtubia@users.noreply.github.com> Date: Thu, 30 May 2024 12:10:36 -0300 Subject: [PATCH] Adds support for show binary log status statement (#638) * feat: adds support for show binary log status statement * feat: adds support for mariadb show binlog status statement --- .../get_primary_show_binary_log_status.yml | 4 ++++ plugins/modules/mysql_replication.py | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/get_primary_show_binary_log_status.yml diff --git a/changelogs/fragments/get_primary_show_binary_log_status.yml b/changelogs/fragments/get_primary_show_binary_log_status.yml new file mode 100644 index 0000000..8757aa1 --- /dev/null +++ b/changelogs/fragments/get_primary_show_binary_log_status.yml @@ -0,0 +1,4 @@ +--- +minor_changes: + + - mysql_replication - Adds support for `SHOW BINARY LOG STATUS` and `SHOW BINLOG STATUS` on getprimary mode. diff --git a/plugins/modules/mysql_replication.py b/plugins/modules/mysql_replication.py index 23c94c1..4f668f2 100644 --- a/plugins/modules/mysql_replication.py +++ b/plugins/modules/mysql_replication.py @@ -297,8 +297,11 @@ queries: import os import warnings +from ansible_collections.community.mysql.plugins.module_utils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.mysql.plugins.module_utils.mysql import ( + get_server_version, + get_server_implementation, mysql_connect, mysql_driver, mysql_driver_fail_msg, @@ -310,10 +313,18 @@ executed_queries = [] def get_primary_status(cursor): - # TODO: when it's available to change on MySQL's side, - # change MASTER to PRIMARY using the approach from - # get_replica_status() function. Same for other functions. - cursor.execute("SHOW MASTER STATUS") + term = "MASTER" + + version = get_server_version(cursor) + server_implementation = get_server_implementation(cursor) + if server_implementation == "mysql" and LooseVersion(version) >= LooseVersion("8.2.0"): + term = "BINARY LOG" + + if server_implementation == "mariadb" and LooseVersion(version) >= LooseVersion("10.5.2"): + term = "BINLOG" + + cursor.execute("SHOW %s STATUS" % term) + primarystatus = cursor.fetchone() return primarystatus