mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-08 19:50:31 -07:00
add a get_server_type module_utils method to detect MySQL vs MariaDB
This commit is contained in:
parent
1e24343375
commit
089e1c3fb1
3 changed files with 16 additions and 6 deletions
|
@ -194,6 +194,16 @@ 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)
|
||||||
|
if 'mariadb' in srv_ver.lower():
|
||||||
|
return "mariadb"
|
||||||
|
else:
|
||||||
|
return "mysql"
|
||||||
|
|
||||||
|
|
||||||
def get_server_version(cursor):
|
def get_server_version(cursor):
|
||||||
"""Returns a string representation of the server version."""
|
"""Returns a string representation of the server version."""
|
||||||
cursor.execute("SELECT VERSION() AS version")
|
cursor.execute("SELECT VERSION() AS version")
|
||||||
|
|
|
@ -16,6 +16,7 @@ from ansible.module_utils.six import iteritems
|
||||||
|
|
||||||
from ansible_collections.community.mysql.plugins.module_utils.mysql import (
|
from ansible_collections.community.mysql.plugins.module_utils.mysql import (
|
||||||
mysql_driver,
|
mysql_driver,
|
||||||
|
get_server_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -883,8 +884,8 @@ def limit_resources(module, cursor, user, host, resource_limits, check_mode):
|
||||||
|
|
||||||
def get_impl(cursor):
|
def get_impl(cursor):
|
||||||
global impl
|
global impl
|
||||||
cursor.execute("SELECT VERSION()")
|
|
||||||
if 'mariadb' in cursor.fetchone()[0].lower():
|
if get_server_type(cursor) == 'mariadb':
|
||||||
from ansible_collections.community.mysql.plugins.module_utils.implementations.mariadb import user as mariauser
|
from ansible_collections.community.mysql.plugins.module_utils.implementations.mariadb import user as mariauser
|
||||||
impl = mariauser
|
impl = mariauser
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -305,7 +305,8 @@ from ansible_collections.community.mysql.plugins.module_utils.mysql import (
|
||||||
mysql_connect,
|
mysql_connect,
|
||||||
mysql_driver,
|
mysql_driver,
|
||||||
mysql_driver_fail_msg,
|
mysql_driver_fail_msg,
|
||||||
mysql_common_argument_spec
|
mysql_common_argument_spec,
|
||||||
|
get_server_type
|
||||||
)
|
)
|
||||||
from ansible_collections.community.mysql.plugins.module_utils.user import (
|
from ansible_collections.community.mysql.plugins.module_utils.user import (
|
||||||
convert_priv_dict_to_str,
|
convert_priv_dict_to_str,
|
||||||
|
@ -407,9 +408,7 @@ class DbServer():
|
||||||
Returns:
|
Returns:
|
||||||
library: Depending on a server type (MySQL or MariaDB).
|
library: Depending on a server type (MySQL or MariaDB).
|
||||||
"""
|
"""
|
||||||
self.cursor.execute("SELECT VERSION()")
|
if get_server_type(cursor) == 'mariadb':
|
||||||
|
|
||||||
if 'mariadb' in self.cursor.fetchone()[0].lower():
|
|
||||||
import ansible_collections.community.mysql.plugins.module_utils.implementations.mariadb.role as role_impl
|
import ansible_collections.community.mysql.plugins.module_utils.implementations.mariadb.role as role_impl
|
||||||
else:
|
else:
|
||||||
import ansible_collections.community.mysql.plugins.module_utils.implementations.mysql.role as role_impl
|
import ansible_collections.community.mysql.plugins.module_utils.implementations.mysql.role as role_impl
|
||||||
|
|
Loading…
Add table
Reference in a new issue