From 1853a3f565f48b9766e4cb6c29e568e368e02019 Mon Sep 17 00:00:00 2001 From: Scott Brown Date: Tue, 17 Jun 2014 13:08:53 -0700 Subject: [PATCH 1/2] BUGFIX 7811: Adding file existence check when performing mysql import on a .gz or .bz2 file, otherwise Ansible will not notice that the underlying *nix command silently died. --- database/mysql_db | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/mysql_db b/database/mysql_db index 8eec1005893..1c67addd1ab 100644 --- a/database/mysql_db +++ b/database/mysql_db @@ -148,9 +148,9 @@ 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 += " -D %s" % pipes.quote(db_name) if os.path.splitext(target)[-1] == '.gz': - cmd = 'gunzip < ' + pipes.quote(target) + ' | ' + cmd + cmd = 'test -e ' + pipes.quote(target) + ' && gunzip < ' + pipes.quote(target) + ' | ' + cmd elif os.path.splitext(target)[-1] == '.bz2': - cmd = 'bunzip2 < ' + pipes.quote(target) + ' | ' + cmd + cmd = 'test -e ' + pipes.quote(target) + ' && bunzip2 < ' + pipes.quote(target) + ' | ' + cmd else: cmd += " < %s" % pipes.quote(target) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) From 34d960ef2005caf61c97406eda4edbdfb5259f5f Mon Sep 17 00:00:00 2001 From: Scott Brown Date: Tue, 17 Jun 2014 14:37:14 -0700 Subject: [PATCH 2/2] BUGFIX 1178: Adding better existence check in one place. db_import now fails fast if target does not exist b/c no point going further without the target. --- database/mysql_db | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/database/mysql_db b/database/mysql_db index 1c67addd1ab..3ac836a7119 100644 --- a/database/mysql_db +++ b/database/mysql_db @@ -140,6 +140,9 @@ def db_dump(module, host, user, password, db_name, target, port, socket=None): return rc, stdout, stderr def db_import(module, host, user, password, db_name, target, port, socket=None): + if not os.path.exists(target): + return module.fail_json(msg="target %s does not exist on the host" % target) + cmd = module.get_bin_path('mysql', True) cmd += " --user=%s --password=%s" % (pipes.quote(user), pipes.quote(password)) if socket is not None: @@ -148,9 +151,9 @@ 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 += " -D %s" % pipes.quote(db_name) if os.path.splitext(target)[-1] == '.gz': - cmd = 'test -e ' + pipes.quote(target) + ' && gunzip < ' + pipes.quote(target) + ' | ' + cmd + cmd = 'gunzip < ' + pipes.quote(target) + ' | ' + cmd elif os.path.splitext(target)[-1] == '.bz2': - cmd = 'test -e ' + pipes.quote(target) + ' && bunzip2 < ' + pipes.quote(target) + ' | ' + cmd + cmd = 'bunzip2 < ' + pipes.quote(target) + ' | ' + cmd else: cmd += " < %s" % pipes.quote(target) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)