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 <akasurde@redhat.com>
This commit is contained in:
parent
a721572206
commit
789b0ef0c9
2 changed files with 5 additions and 5 deletions
|
@ -2710,7 +2710,7 @@ class AnsibleModule(object):
|
||||||
:kw data: If given, information to write to the stdin of the command
|
: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 binary_data: If False, append a newline to the data. Default False
|
||||||
:kw path_prefix: If given, additional path to find the command in.
|
: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
|
the same directory can also be found
|
||||||
:kw cwd: If given, working directory to run the command inside
|
:kw cwd: If given, working directory to run the command inside
|
||||||
:kw use_unsafe_shell: See `args` parameter. Default False
|
:kw use_unsafe_shell: See `args` parameter. Default False
|
||||||
|
|
|
@ -177,7 +177,7 @@ def preflight_validation(bin_path, project_path, variables_args=None, plan_file=
|
||||||
if not os.path.isdir(project_path):
|
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))
|
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:
|
if rc != 0:
|
||||||
module.fail_json(msg="Failed to validate Terraform configuration files:\r\n{0}".format(err))
|
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]
|
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(['-target', t])
|
||||||
|
|
||||||
command.extend(_state_args(state_file))
|
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:
|
if rc == 0:
|
||||||
# no changes
|
# no changes
|
||||||
|
@ -320,7 +320,7 @@ def main():
|
||||||
for k, v in variables.items():
|
for k, v in variables.items():
|
||||||
variables_args.extend([
|
variables_args.extend([
|
||||||
'-var',
|
'-var',
|
||||||
shlex_quote('{0}={1}'.format(k, v))
|
'{0}={1}'.format(k, v)
|
||||||
])
|
])
|
||||||
if variables_file:
|
if variables_file:
|
||||||
variables_args.extend(['-var-file', variables_file])
|
variables_args.extend(['-var-file', variables_file])
|
||||||
|
|
Loading…
Reference in a new issue