Skip to content

Commit 12c4256

Browse files
committed
Fix JSON quoting bug
Quotes around the extra-vars JSON only make sense in a shell. Shells strip those quotes off and pass the whole thing in to the application. Ansible couldn't parse or understand the JSON with the quotes in place, so remove them and fix the tests accordingly.
1 parent b4c903e commit 12c4256

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

actions/lib/ansible_base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _parse_extra_vars(self):
6868

6969
# Add --extra-vars for each json object
7070
elif t == 'json':
71-
self.args.append("--extra-vars='{0}'".format(json.dumps(v)))
71+
self.args.append("--extra-vars={0}".format(json.dumps(v)))
7272

7373
# Combine contiguous kwarg vars into a single space-separated --extra-vars kwarg
7474
elif t == 'kwarg' and last != t:
@@ -114,17 +114,14 @@ def _json_output_arg(self):
114114
def handle_json_arg(self):
115115
pass
116116

117-
def popen_call(self, p):
118-
return p.wait()
119-
120117
def execute(self):
121118
"""
122119
Execute the command and stream stdout and stderr output
123120
from child process as it appears without delay.
124121
Terminate with child's exit code.
125122
"""
126-
p = subprocess.Popen(self.cmd, env=os.environ.copy(), stdout=self.stdout)
127-
exit_code = self.popen_call(p)
123+
124+
exit_code = subprocess.call(self.cmd, env=os.environ.copy(), stdout=self.stdout)
128125
if exit_code is not 0:
129126
sys.stderr.write('Executed command "%s"\n' % ' '.join(self.cmd))
130127

tests/test_actions_lib_ansiblebaserunner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def extra_vars_json_yaml_fixture(self, test_name):
8686
test_yaml = self.load_yaml('extra_vars_json.yaml')
8787
test = next(t for t in test_yaml if t['name'] == test_name)
8888
case = test['test']
89-
expected = ['--extra-vars=\'{}\''.format(json.dumps(e)) for e in case]
89+
expected = ['--extra-vars={}'.format(json.dumps(e)) for e in case]
9090
self.check_arg_parse(arg, case, expected)
9191

9292
def test_parse_extra_vars_json_yaml_dict(self):
@@ -115,7 +115,7 @@ def extra_vars_complex_yaml_fixture(self, test_name):
115115
# this does not preserve the order exactly, but it shows that elements are correctly parsed
116116
expected = ['--extra-vars={}'.format(e)
117117
for e in test['expected'] if isinstance(e, six.string_types)]
118-
expected.extend(['--extra-vars=\'{}\''.format(json.dumps(e))
118+
expected.extend(['--extra-vars={}'.format(json.dumps(e))
119119
for e in test['expected'] if isinstance(e, dict)])
120120
self.check_arg_parse(arg, case, expected)
121121

0 commit comments

Comments
 (0)