From 3da5b34006cc4a14b11b4e3d00f72bf2b3375056 Mon Sep 17 00:00:00 2001 From: Laurent Indermuehle Date: Wed, 11 Oct 2023 15:55:29 +0200 Subject: [PATCH] add utils function to get server type (MySQL vs MariaDB) --- plugins/module_utils/mysql.py | 7 +++++++ plugins/module_utils/user.py | 1 + 2 files changed, 8 insertions(+) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index b95d20d0d..d2c7f7934 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -194,6 +194,13 @@ def mysql_common_argument_spec(): ) +def get_server_type(cursor): + """ Return MySQL or MariaDB after quering the server + using SELECT VERSION()""" + srv_ver = get_server_version(cursor) + return 'mariadb' if 'mariadb' in srv_ver.lower() else "mysql" + + def get_server_version(cursor): """Returns a string representation of the server version.""" cursor.execute("SELECT VERSION() AS version") diff --git a/plugins/module_utils/user.py b/plugins/module_utils/user.py index c78a694c6..6662d0ff0 100644 --- a/plugins/module_utils/user.py +++ b/plugins/module_utils/user.py @@ -16,6 +16,7 @@ from ansible_collections.community.mysql.plugins.module_utils.mysql import ( mysql_driver, + get_server_type, )