diff options
author | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-05-27 20:27:51 -0700 |
---|---|---|
committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-05-27 20:28:19 -0700 |
commit | 2b5e932cfb4df42f46812aee2476fdf5aabab172 (patch) | |
tree | e75e462bf8f404e49fb383143ad98030a4673479 | |
parent | 415815ef4581b2ca92b12218462e7e127ed0ac29 (diff) | |
download | ansible-modules-core-2b5e932cfb4df42f46812aee2476fdf5aabab172.tar.gz |
Fix for the new import code when password is empty
-rw-r--r-- | database/mysql/mysql_db.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/database/mysql/mysql_db.py b/database/mysql/mysql_db.py index b9d862b5..a76c4526 100644 --- a/database/mysql/mysql_db.py +++ b/database/mysql/mysql_db.py @@ -164,14 +164,19 @@ def db_import(module, host, user, password, db_name, target, all_databases, port 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)) + cmd = [module.get_bin_path('mysql', True)] + if user: + cmd.append("--user=%s" % pipes.quote(user)) + if password: + cmd.append("--password=%s" % pipes.quote(password)) if socket is not None: - cmd += " --socket=%s" % pipes.quote(socket) + cmd.append("--socket=%s" % pipes.quote(socket)) else: - cmd += " --host=%s --port=%i" % (pipes.quote(host), port) + cmd.append("--host=%s" % pipes.quote(host)) + cmd.append("--port=%i" % port) if not all_databases: - cmd += " -D %s" % pipes.quote(db_name) + cmd.append("-D") + cmd.append(pipes.quote(db_name)) comp_prog_path = None if os.path.splitext(target)[-1] == '.gz': @@ -183,7 +188,7 @@ def db_import(module, host, user, password, db_name, target, all_databases, port if comp_prog_path: p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p2 = subprocess.Popen(cmd, stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout2, stderr2) = p2.communicate() p1.stdout.close() p1.wait() @@ -193,6 +198,7 @@ def db_import(module, host, user, password, db_name, target, all_databases, port else: return p2.returncode, stdout2, stderr2 else: + cmd = ' '.join(cmd) cmd += " < %s" % pipes.quote(target) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) return rc, stdout, stderr |