From 789b0ef0c948dd2fb6e34452885b7aa8bbe3cd74 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 20 Nov 2018 10:31:54 +0530 Subject: [PATCH] Pass string command in run_command (#48805) When there are spaces in command args passed as a list, then run_command and underlying subprocess fails. This can be overcome by passing command as string rather than list. Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/basic.py | 2 +- lib/ansible/modules/cloud/misc/terraform.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 4a79b5424a..c8fd190ebe 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -2710,7 +2710,7 @@ class AnsibleModule(object): :kw data: If given, information to write to the stdin of the command :kw binary_data: If False, append a newline to the data. Default False :kw path_prefix: If given, additional path to find the command in. - This adds to the PATH environment vairable so helper commands in + This adds to the PATH environment variable so helper commands in the same directory can also be found :kw cwd: If given, working directory to run the command inside :kw use_unsafe_shell: See `args` parameter. Default False diff --git a/lib/ansible/modules/cloud/misc/terraform.py b/lib/ansible/modules/cloud/misc/terraform.py index 46003ca3ec..36e29a975d 100644 --- a/lib/ansible/modules/cloud/misc/terraform.py +++ b/lib/ansible/modules/cloud/misc/terraform.py @@ -177,7 +177,7 @@ def preflight_validation(bin_path, project_path, variables_args=None, plan_file= if not os.path.isdir(project_path): module.fail_json(msg="Path for Terraform project '{0}' doesn't exist on this host - check the path and try again please.".format(project_path)) - rc, out, err = module.run_command([bin_path, 'validate'] + variables_args, cwd=project_path) + rc, out, err = module.run_command([bin_path, 'validate'] + variables_args, cwd=project_path, use_unsafe_shell=True) if rc != 0: module.fail_json(msg="Failed to validate Terraform configuration files:\r\n{0}".format(err)) @@ -246,12 +246,12 @@ def build_plan(bin_path, project_path, variables_args, state_file, targets, plan command = [bin_path, 'plan', '-input=false', '-no-color', '-detailed-exitcode', '-out', plan_path] - for t in (module.params.get('targets') or []): + for t in (targets or []): command.extend(['-target', t]) command.extend(_state_args(state_file)) - rc, out, err = module.run_command(command + variables_args, cwd=project_path) + rc, out, err = module.run_command(command + variables_args, cwd=project_path, use_unsafe_shell=True) if rc == 0: # no changes @@ -320,7 +320,7 @@ def main(): for k, v in variables.items(): variables_args.extend([ '-var', - shlex_quote('{0}={1}'.format(k, v)) + '{0}={1}'.format(k, v) ]) if variables_file: variables_args.extend(['-var-file', variables_file])