From ec6f488d1f22fac944db5e207bb19e60c0fd08f1 Mon Sep 17 00:00:00 2001 From: Matthew Williams Date: Fri, 30 Mar 2012 09:18:10 -0700 Subject: [PATCH] shell quoting fixes (edited author's original commit comment -- MPD) --- lib/ansible/playbook.py | 2 +- lib/ansible/utils.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index a1e5ac2bf35..6c9ef9fb3f5 100755 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -293,7 +293,7 @@ class PlayBook(object): async_seconds = int(task.get('async', 0)) # not async by default async_poll_interval = int(task.get('poll', 10)) # default poll = 10 seconds - tokens = shlex.split(action) + tokens = shlex.split(action, posix=False) module_name = tokens[0] module_args = tokens[1:] diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index 7f602f88f94..9d0b68ff8ec 100755 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -260,12 +260,19 @@ def parse_yaml_from_file(path): raise errors.AnsibleError("file not found: %s" % path) return parse_yaml(data) -def parse_kv(args): +def unquote_string(string): + ''' remove single or double quotes from beginning/end of string''' + if (string.startswith('"') and string.endswith('"')) or \ + (string.startswith("'") and string.endswith("'")): + return string[1:-1] + else: + return string + +def parse_kv(args, unquote=True): ''' convert a string of key/value items to a dict ''' options = {} for x in args: if x.find("=") != -1: k, v = x.split("=") - options[k]=v + options[k]=unquote_string(v) if unquote else v return options -