From a7de8f89c4e8575989f4fe1bb7c6dc8899ccc65a Mon Sep 17 00:00:00 2001 From: William Welter Date: Thu, 4 Jan 2024 13:38:38 +0000 Subject: [PATCH] Using `show all slaves status` whe using MariaDB to be consistent with the MySQL behaviour. --- plugins/modules/mysql_info.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/plugins/modules/mysql_info.py b/plugins/modules/mysql_info.py index 73e403a..1038f33 100644 --- a/plugins/modules/mysql_info.py +++ b/plugins/modules/mysql_info.py @@ -5,6 +5,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = r''' @@ -325,9 +326,10 @@ class MySQL_Info(object): 5. add info about the new subset with an example to RETURN block """ - def __init__(self, module, cursor): + def __init__(self, module, cursor, server_implementation): self.module = module self.cursor = cursor + self.server_implementation = server_implementation self.info = { 'version': {}, 'databases': {}, @@ -387,6 +389,18 @@ class MySQL_Info(object): self.__collect(exclude_fields, return_empty_dbs, set(self.info)) return self.info + def is_mariadb(self): + if self.server_implementation == "mariadb": + return True + else: + return False + + def is_mysql(self): + if self.server_implementation == "mysql": + return True + else: + return False + def __collect(self, exclude_fields, return_empty_dbs, wanted): """Collect all possible subsets.""" if 'version' in wanted or 'settings' in wanted: @@ -497,7 +511,10 @@ class MySQL_Info(object): def __get_slave_status(self): """Get slave status if the instance is a slave.""" - res = self.__exec_sql('SHOW SLAVE STATUS') + if(self.is_mariadb()): + res = self.__exec_sql('SHOW ALL SLAVES STATUS') + else: + res = self.__exec_sql('SHOW SLAVE STATUS') if res: for line in res: host = line['Master_Host'] @@ -738,10 +755,16 @@ def main(): 'Exception message: %s' % (connector_name, connector_version, config_file, to_native(e))) module.fail_json(msg) + cursor.execute("SELECT VERSION()") + if 'mariadb' in cursor.fetchone()[0].lower(): + server_implementation="mariadb" + else: + server_implementation="mysql" + ############################### # Create object and do main job - mysql = MySQL_Info(module, cursor) + mysql = MySQL_Info(module, cursor, server_implementation) module.exit_json(changed=False, connector_name=connector_name,