1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

mysql_db module now correctly fails on import if bz2 or gz fails.

This commit is contained in:
Jonathan Mainguy 2014-03-30 13:39:00 -04:00
parent 2f75662a47
commit bb73819c43

View file

@ -148,9 +148,39 @@ def db_import(module, host, user, password, db_name, target, port, socket=None):
cmd += " --host=%s --port=%s" % (pipes.quote(host), pipes.quote(port)) cmd += " --host=%s --port=%s" % (pipes.quote(host), pipes.quote(port))
cmd += " -D %s" % pipes.quote(db_name) cmd += " -D %s" % pipes.quote(db_name)
if os.path.splitext(target)[-1] == '.gz': if os.path.splitext(target)[-1] == '.gz':
cmd = 'gunzip < ' + pipes.quote(target) + ' | ' + cmd gunzip_path = module.get_bin_path('gunzip')
if gunzip_path:
rc, stdout, stderr = module.run_command('%s %s' % (gunzip_path, target))
if rc != 0:
return rc, stdout, stderr
cmd += " < %s" % pipes.quote(target[0:-3])
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
if rc != 0:
return rc, stdout, stderr
gzip_path = module.get_bin_path('gzip')
if gzip_path:
rc, stdout, stderr = module.run_command('%s %s' % (gzip_path, target[0:-3]))
else:
module.fail_json(msg="gzip command not found")
else:
module.fail_json(msg="gunzip command not found")
elif os.path.splitext(target)[-1] == '.bz2': elif os.path.splitext(target)[-1] == '.bz2':
cmd = 'bunzip2 < ' + pipes.quote(target) + ' | ' + cmd bunzip2_path = module.get_bin_path('bunzip2')
if bunzip2_path:
rc, stdout, stderr = module.run_command('%s %s' % (bunzip2_path, target))
if rc != 0:
return rc, stdout, stderr
cmd += " < %s" % pipes.quote(target[0:-4])
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
if rc != 0:
return rc, stdout, stderr
bzip2_path = module.get_bin_path('bzip2')
if bzip2_path:
rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, target[0:-4]))
else:
module.fail_json(msg="bzip2 command not found")
else:
module.fail_json(msg="bunzip2 command not found")
else: else:
cmd += " < %s" % pipes.quote(target) cmd += " < %s" % pipes.quote(target)
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)