mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-05 10:10:32 -07:00
refactor to improve command determination with error handling
Previous code felt into Unknown server implementation for MariaDB < 10.4.6
This commit is contained in:
parent
b1e816ef1e
commit
4d4475b2de
1 changed files with 14 additions and 12 deletions
|
@ -387,12 +387,13 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
|
||||||
dump_extra_args=None, unsafe_password=False, restrict_config_file=False,
|
dump_extra_args=None, unsafe_password=False, restrict_config_file=False,
|
||||||
check_implicit_admin=False, pipefail=False):
|
check_implicit_admin=False, pipefail=False):
|
||||||
|
|
||||||
if server_implementation == 'mysql':
|
cmd_str = 'mysqldump'
|
||||||
cmd = module.get_bin_path('mysqldump', True)
|
if server_implementation == 'mariadb' and LooseVersion(server_version) >= LooseVersion("10.4.6"):
|
||||||
elif server_implementation == 'mariadb' and LooseVersion(server_version) >= LooseVersion("10.4.6"):
|
cmd_str = 'mariadb-dump'
|
||||||
cmd = module.get_bin_path('mariadb-dump', True)
|
try:
|
||||||
else:
|
cmd = module.get_bin_path(cmd_str, True)
|
||||||
return module.fail_json(msg="Unknown server implementation %s" % server_implementation)
|
except Exception as e:
|
||||||
|
return 1, "", "Error determining dump command: %s" % str(e)
|
||||||
|
|
||||||
# If defined, mysqldump demands --defaults-extra-file be the first option
|
# If defined, mysqldump demands --defaults-extra-file be the first option
|
||||||
if config_file:
|
if config_file:
|
||||||
|
@ -490,12 +491,13 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
||||||
if not os.path.exists(target):
|
if not os.path.exists(target):
|
||||||
return module.fail_json(msg="target %s does not exist on the host" % target)
|
return module.fail_json(msg="target %s does not exist on the host" % target)
|
||||||
|
|
||||||
if server_implementation == 'mysql':
|
cmd_str = 'mysql'
|
||||||
cmd = [module.get_bin_path('mysql', True)]
|
if server_implementation == 'mariadb' and LooseVersion(server_version) >= LooseVersion("10.4.6"):
|
||||||
elif server_implementation == 'mariadb' and LooseVersion(server_version) >= LooseVersion("10.4.6"):
|
cmd_str = 'mariadb'
|
||||||
cmd = [module.get_bin_path('mariadb', True)]
|
try:
|
||||||
else:
|
cmd = module.get_bin_path(cmd_str, True)
|
||||||
return module.fail_json(msg="Unknown server implementation %s" % server_implementation)
|
except Exception as e:
|
||||||
|
return 1, "", "Error determining mysql/mariadb command: %s" % str(e)
|
||||||
|
|
||||||
# --defaults-file must go first, or errors out
|
# --defaults-file must go first, or errors out
|
||||||
if config_file:
|
if config_file:
|
||||||
|
|
Loading…
Add table
Reference in a new issue