... | ... |
@@ -28,7 +28,7 @@ from ansible import __version__ |
28 | 28 |
from ansible.utils.display_functions import * |
29 | 29 |
from ansible.utils.plugins import * |
30 | 30 |
from ansible.callbacks import display |
31 |
-from ansible.utils.splitter import split_args |
|
31 |
+from ansible.utils.splitter import split_args, unquote |
|
32 | 32 |
import ansible.constants as C |
33 | 33 |
import ast |
34 | 34 |
import time |
... | ... |
@@ -418,28 +418,6 @@ def merge_module_args(current_args, new_args): |
418 | 418 |
module_args = "%s=%s %s" % (k, pipes.quote(v), module_args) |
419 | 419 |
return module_args.strip() |
420 | 420 |
|
421 |
-def smush_braces(data): |
|
422 |
- ''' smush Jinaj2 braces so unresolved templates like {{ foo }} don't get parsed weird by key=value code ''' |
|
423 |
- while '{{ ' in data: |
|
424 |
- data = data.replace('{{ ', '{{') |
|
425 |
- while ' }}' in data: |
|
426 |
- data = data.replace(' }}', '}}') |
|
427 |
- return data |
|
428 |
- |
|
429 |
-def smush_ds(data): |
|
430 |
- # things like key={{ foo }} are not handled by shlex.split well, so preprocess any YAML we load |
|
431 |
- # so we do not have to call smush elsewhere |
|
432 |
- if type(data) == list: |
|
433 |
- return [ smush_ds(x) for x in data ] |
|
434 |
- elif type(data) == dict: |
|
435 |
- for (k,v) in data.items(): |
|
436 |
- data[k] = smush_ds(v) |
|
437 |
- return data |
|
438 |
- elif isinstance(data, basestring): |
|
439 |
- return smush_braces(data) |
|
440 |
- else: |
|
441 |
- return data |
|
442 |
- |
|
443 | 421 |
def parse_yaml(data, path_hint=None): |
444 | 422 |
''' convert a yaml string to a data structure. Also supports JSON, ssssssh!!!''' |
445 | 423 |
|
... | ... |
@@ -458,7 +436,7 @@ def parse_yaml(data, path_hint=None): |
458 | 458 |
# else this is pretty sure to be a YAML document |
459 | 459 |
loaded = yaml.safe_load(data) |
460 | 460 |
|
461 |
- return smush_ds(loaded) |
|
461 |
+ return loaded |
|
462 | 462 |
|
463 | 463 |
def process_common_errors(msg, probline, column): |
464 | 464 |
replaced = probline.replace(" ","") |
... | ... |
@@ -640,7 +618,7 @@ def parse_kv(args): |
640 | 640 |
# attempting to split a unicode here does bad things |
641 | 641 |
args = args.encode('utf-8') |
642 | 642 |
try: |
643 |
- vargs = shlex.split(args, posix=True) |
|
643 |
+ vargs = split_args(args) |
|
644 | 644 |
except ValueError, ve: |
645 | 645 |
if 'no closing quotation' in str(ve).lower(): |
646 | 646 |
raise errors.AnsibleError("error parsing argument string, try quoting the entire line.") |
... | ... |
@@ -650,7 +628,7 @@ def parse_kv(args): |
650 | 650 |
for x in vargs: |
651 | 651 |
if "=" in x: |
652 | 652 |
k, v = x.split("=",1) |
653 |
- options[k] = v |
|
653 |
+ options[k] = unquote(v) |
|
654 | 654 |
return options |
655 | 655 |
|
656 | 656 |
def merge_hash(a, b): |
... | ... |
@@ -149,3 +149,9 @@ def split_args(args): |
149 | 149 |
params = [x.decode('utf-8') for x in params] |
150 | 150 |
return params |
151 | 151 |
|
152 |
+def unquote(data): |
|
153 |
+ ''' removes first and last quotes from a string, if the string starts and ends with the same quotes ''' |
|
154 |
+ if len(data) > 0 and (data[0] == '"' and data[-1] == '"' or data[0] == "'" and data[-1] == "'"): |
|
155 |
+ return data[1:-1] |
|
156 |
+ return data |
|
157 |
+ |
... | ... |
@@ -245,24 +245,6 @@ class TestUtils(unittest.TestCase): |
245 | 245 |
# Just a string |
246 | 246 |
self.assertEqual(ansible.utils.parse_json('foo'), dict(failed=True, parsed=False, msg='foo')) |
247 | 247 |
|
248 |
- def test_smush_braces(self): |
|
249 |
- self.assertEqual(ansible.utils.smush_braces('{{ foo}}'), '{{foo}}') |
|
250 |
- self.assertEqual(ansible.utils.smush_braces('{{foo }}'), '{{foo}}') |
|
251 |
- self.assertEqual(ansible.utils.smush_braces('{{ foo }}'), '{{foo}}') |
|
252 |
- |
|
253 |
- def test_smush_ds(self): |
|
254 |
- # list |
|
255 |
- self.assertEqual(ansible.utils.smush_ds(['foo={{ foo }}']), ['foo={{foo}}']) |
|
256 |
- |
|
257 |
- # dict |
|
258 |
- self.assertEqual(ansible.utils.smush_ds(dict(foo='{{ foo }}')), dict(foo='{{foo}}')) |
|
259 |
- |
|
260 |
- # string |
|
261 |
- self.assertEqual(ansible.utils.smush_ds('foo={{ foo }}'), 'foo={{foo}}') |
|
262 |
- |
|
263 |
- # int |
|
264 |
- self.assertEqual(ansible.utils.smush_ds(0), 0) |
|
265 |
- |
|
266 | 248 |
def test_parse_yaml(self): |
267 | 249 |
#json |
268 | 250 |
self.assertEqual(ansible.utils.parse_yaml('{"foo": "bar"}'), dict(foo='bar')) |
... | ... |
@@ -680,7 +662,6 @@ class TestUtils(unittest.TestCase): |
680 | 680 |
|
681 | 681 |
def test_split_args(self): |
682 | 682 |
# split_args is a smarter shlex.split for the needs of the way ansible uses it |
683 |
- # TODO: FIXME: should this survive, retire smush_ds |
|
684 | 683 |
|
685 | 684 |
def _split_info(input, desired, actual): |
686 | 685 |
print "SENT: ", input |