Skip to content

Commit a7de8f8

Browse files
committed
Using show all slaves status whe using MariaDB to be consistent
with the MySQL behaviour.
1 parent 81ab18d commit a7de8f8

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

plugins/modules/mysql_info.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
66

77
from __future__ import absolute_import, division, print_function
8+
89
__metaclass__ = type
910

1011
DOCUMENTATION = r'''
@@ -325,9 +326,10 @@ class MySQL_Info(object):
325326
5. add info about the new subset with an example to RETURN block
326327
"""
327328

328-
def __init__(self, module, cursor):
329+
def __init__(self, module, cursor, server_implementation):
329330
self.module = module
330331
self.cursor = cursor
332+
self.server_implementation = server_implementation
331333
self.info = {
332334
'version': {},
333335
'databases': {},
@@ -387,6 +389,18 @@ def get_info(self, filter_, exclude_fields, return_empty_dbs):
387389
self.__collect(exclude_fields, return_empty_dbs, set(self.info))
388390
return self.info
389391

392+
def is_mariadb(self):
393+
if self.server_implementation == "mariadb":
394+
return True
395+
else:
396+
return False
397+
398+
def is_mysql(self):
399+
if self.server_implementation == "mysql":
400+
return True
401+
else:
402+
return False
403+
390404
def __collect(self, exclude_fields, return_empty_dbs, wanted):
391405
"""Collect all possible subsets."""
392406
if 'version' in wanted or 'settings' in wanted:
@@ -497,7 +511,10 @@ def __get_master_status(self):
497511

498512
def __get_slave_status(self):
499513
"""Get slave status if the instance is a slave."""
500-
res = self.__exec_sql('SHOW SLAVE STATUS')
514+
if(self.is_mariadb()):
515+
res = self.__exec_sql('SHOW ALL SLAVES STATUS')
516+
else:
517+
res = self.__exec_sql('SHOW SLAVE STATUS')
501518
if res:
502519
for line in res:
503520
host = line['Master_Host']
@@ -738,10 +755,16 @@ def main():
738755
'Exception message: %s' % (connector_name, connector_version, config_file, to_native(e)))
739756
module.fail_json(msg)
740757

758+
cursor.execute("SELECT VERSION()")
759+
if 'mariadb' in cursor.fetchone()[0].lower():
760+
server_implementation="mariadb"
761+
else:
762+
server_implementation="mysql"
763+
741764
###############################
742765
# Create object and do main job
743766

744-
mysql = MySQL_Info(module, cursor)
767+
mysql = MySQL_Info(module, cursor, server_implementation)
745768

746769
module.exit_json(changed=False,
747770
connector_name=connector_name,

0 commit comments

Comments
 (0)