From dd4838e4aadc8f1310aa2743558f343832aab876 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 25 May 2015 09:22:08 -0700 Subject: [PATCH] Refactor dump compression and use get_bin_path for finding the compressors --- lib/ansible/modules/database/mysql/mysql_db.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/database/mysql/mysql_db.py b/lib/ansible/modules/database/mysql/mysql_db.py index b28ef219f6..0cf0ea5c61 100644 --- a/lib/ansible/modules/database/mysql/mysql_db.py +++ b/lib/ansible/modules/database/mysql/mysql_db.py @@ -143,14 +143,20 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port, cmd += " --all-databases" else: cmd += " %s" % pipes.quote(db_name) + + path = None if os.path.splitext(target)[-1] == '.gz': - cmd = cmd + ' | gzip > ' + pipes.quote(target) + path = module.get_bin_path('gzip', True) elif os.path.splitext(target)[-1] == '.bz2': - cmd = cmd + ' | bzip2 > ' + pipes.quote(target) + path = module.get_bin_path('bzip2', True) elif os.path.splitext(target)[-1] == '.xz': - cmd = cmd + ' | xz > ' + pipes.quote(target) + path = module.get_bin_path('xz', True) + + if path: + cmd = '%s | %s > %s' % (cmd, path, pipes.quote(target)) else: cmd += " > %s" % pipes.quote(target) + rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) return rc, stdout, stderr