Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template module does not know tojson filter #25381

Closed
pdesgarets opened this issue Jun 6, 2017 · 1 comment
Closed

Template module does not know tojson filter #25381

pdesgarets opened this issue Jun 6, 2017 · 1 comment
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module.

Comments

@pdesgarets
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Ansible template module

ANSIBLE VERSION
ansible-playbook 2.3.1.0
  config file =
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Dec 18 2016, 07:03:39) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

(does not happen with ansible 2.3.0.0)

CONFIGURATION

Default config.

OS / ENVIRONMENT

macOS 10.12.4

SUMMARY

Filter tojson does not seem to work. When using it with template module

STEPS TO REPRODUCE
---
- hosts: localhost
  tasks:
  - template:
      src: /tmp/template.test
      dest: /tmp/output

with /tmp/template.test as following :

{{ true|tojson }}
EXPECTED RESULTS

/tmp/output is created containing true

ACTUAL RESULTS

An error occurs :

Using module file /usr/local/Cellar/ansible/2.3.1.0/libexec/lib/python2.7/site-packages/ansible/modules/files/stat.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: admin
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/admin/.ansible/tmp/ansible-tmp-1496744303.52-214315117579909 `" && echo ansible-tmp-1496744303.52-214315117579909="` echo /Users/admin/.ansible/tmp/ansible-tmp-1496744303.52-214315117579909 `" ) && sleep 0'
<127.0.0.1> PUT /var/folders/gr/2wwtn6x534qb6s2g11tgxv140000gn/T/tmp_DbcuK TO /Users/admin/.ansible/tmp/ansible-tmp-1496744303.52-214315117579909/stat.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/admin/.ansible/tmp/ansible-tmp-1496744303.52-214315117579909/ /Users/admin/.ansible/tmp/ansible-tmp-1496744303.52-214315117579909/stat.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/local/Cellar/ansible/2.3.1.0/libexec/bin/python2.7 /Users/admin/.ansible/tmp/ansible-tmp-1496744303.52-214315117579909/stat.py; rm -rf "/Users/admin/.ansible/tmp/ansible-tmp-1496744303.52-214315117579909/" > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "AnsibleError: template error while templating string: no filter named 'tojson'. String: {{ True|tojson }}\n"
}
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Jun 6, 2017
@sivel
Copy link
Member

sivel commented Jun 6, 2017

The tojson filter provided by upstream jinja2 Is part of the jinja2 version 2.9 release.

However ansible also ships with a filter to do this, which is named to_json and to_nice_json

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this as completed Jun 6, 2017
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Jun 12, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module.
Projects
None yet
Development

No branches or pull requests

4 participants