From 407d76b8d5efe7550f6ae509fb24b3a1d0399426 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 16 Dec 2015 18:21:47 -0500 Subject: [PATCH] Fixing template integration test for python 2.6 versions No longer immediately fallback to to_json if simplejson is not installed --- lib/ansible/plugins/filter/core.py | 4 +++- test/integration/roles/test_template/tasks/main.yml | 5 ----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index d5e1a12e531..40ffb23fa48 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -100,9 +100,11 @@ def to_nice_json(a, *args, **kw): else: if major >= 2: return simplejson.dumps(a, indent=4, sort_keys=True, *args, **kw) + try: + return json.dumps(a, indent=4, sort_keys=True, cls=AnsibleJSONEncoder, *args, **kw) + except: # Fallback to the to_json filter return to_json(a, *args, **kw) - return json.dumps(a, indent=4, sort_keys=True, cls=AnsibleJSONEncoder, *args, **kw) def bool(a): ''' return a bool for the arg ''' diff --git a/test/integration/roles/test_template/tasks/main.yml b/test/integration/roles/test_template/tasks/main.yml index a35b93d9d92..9fd1d860e00 100644 --- a/test/integration/roles/test_template/tasks/main.yml +++ b/test/integration/roles/test_template/tasks/main.yml @@ -48,11 +48,6 @@ - name: copy known good into place copy: src=foo.txt dest={{output_dir}}/foo.txt - when: pyver.stdout != '2.6' - -- name: copy known good into place - copy: src=foo-py26.txt dest={{output_dir}}/foo.txt - when: pyver.stdout == '2.6' - name: compare templated file to known good shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt