From ecae636160ca1c81e9c2151264ba754a8bed6a9e Mon Sep 17 00:00:00 2001 From: Jens Peter Schroer Date: Fri, 23 Oct 2015 14:21:46 +0200 Subject: [PATCH 1/2] allowing json in lookup template calls --- lib/ansible/plugins/lookup/template.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/lookup/template.py b/lib/ansible/plugins/lookup/template.py index 5fc10d7f52..56a33a9d17 100644 --- a/lib/ansible/plugins/lookup/template.py +++ b/lib/ansible/plugins/lookup/template.py @@ -27,6 +27,7 @@ class LookupModule(LookupBase): def run(self, terms, variables, **kwargs): + convert_data_p = kwargs.get('convert_data', True) basedir = self.get_basedir(variables) ret = [] @@ -46,7 +47,7 @@ class LookupModule(LookupBase): searchpath.insert(1, variables['role_path']) self._templar.environment.loader.searchpath = searchpath - res = self._templar.template(template_data, preserve_trailing_newlines=True) + res = self._templar.template(template_data, preserve_trailing_newlines=True,convert_data=convert_data_p) ret.append(res) else: raise AnsibleError("the template file %s could not be found for the lookup" % term) From 9f2baf3f8496b01f04973b0f0d41dbf2867e7768 Mon Sep 17 00:00:00 2001 From: Jens Peter Schroer Date: Fri, 30 Oct 2015 10:34:47 +0100 Subject: [PATCH 2/2] adding documentation --- docsite/rst/playbooks_lookups.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docsite/rst/playbooks_lookups.rst b/docsite/rst/playbooks_lookups.rst index 9638411a1a..fc6559e0e6 100644 --- a/docsite/rst/playbooks_lookups.rst +++ b/docsite/rst/playbooks_lookups.rst @@ -271,6 +271,10 @@ Here are some examples:: - debug: msg="{{ lookup('template', './some_template.j2') }} is a value from evaluation of this template" + # loading a json file from a template as a string + - debug: msg="{{ lookup('template', './some_json.json.j2', convert_data=False) }} is a value from evaluation of this template" + + - debug: msg="{{ lookup('etcd', 'foo') }} is a value from a locally running etcd" # shelvefile lookup retrieves a string value corresponding to a key inside a Python shelve file