From 011395158043daf1643ec7b07b43e8c72cbafdb4 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 10 Apr 2013 16:26:59 -0400 Subject: [PATCH] Enable usage of when_set within new eval system. --- lib/ansible/runner/lookup_plugins/nested.py | 5 +++++ lib/ansible/utils/__init__.py | 14 ++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/ansible/runner/lookup_plugins/nested.py b/lib/ansible/runner/lookup_plugins/nested.py index bd66a5f27c..0fb296f7f4 100644 --- a/lib/ansible/runner/lookup_plugins/nested.py +++ b/lib/ansible/runner/lookup_plugins/nested.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from ansible.utils import safe_eval def flatten(terms): ret = [] @@ -40,6 +41,10 @@ class LookupModule(object): pass def run(self, terms, **kwargs): + if '{' or '[' in terms: + # Jinja2-ified list needs to be converted back to a real type + # TODO: something a bit less heavy than eval + terms = safe_eval(terms) if not isinstance(terms, list): raise errors.AnsibleError("a list is required for with_nested") my_list = terms[:] diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index 7951c916e7..5ed717601d 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -154,11 +154,6 @@ def check_conditional(conditional): if not isinstance(conditional, basestring): return conditional - def is_set(var): - return not var.startswith("$") and not '{{' in var - - def is_unset(var): - return var.startswith("$") or '{{' in var try: conditional = conditional.replace("\n", "\\n") @@ -693,14 +688,17 @@ def safe_eval(str): the env is constrained) ''' # FIXME: is there a more native way to do this? + + def is_set(var): + return not var.startswith("$") and not '{{' in var + def is_unset(var): + return var.startswith("$") or '{{' in var - # do not allow method calls + # do not allow method calls to modules if re.search(r'\w\.\w+\(', str): - print "C1" return str # do not allow imports if re.search(r'import \w+', str): - print "C2" return str return eval(str)