template module setting variables to unicode

888 views
Skip to first unread message

Henry Mendez

unread,
Jun 14, 2016, 1:54:17 PM6/14/16
to Ansible Project
Hi,

I've recently updated from 1.9.1 to 2.0.2.0. I use the template module a lot to build configs for my app. After updating, when I generate my templates, the data structure variables are being rendered as unicode strings.

Versions:
ansible 2.0.2.0
PyYAML==3.11
Jinja2==2.8

Example:
File with variables:
---
my_list:
    - var1

Template file:
app.config.j2
'MYLIST': '{{my_list}}'

ansible command:
ansible localhost -m template -a "src=app.config.j2 dest=/tmp/app.config"

Contents of app.config:
'MYLIST': '[u'var1']'

What I used to get: (Version 1.9.1)
'MYLIST': '['var1']'

If I change my env file to be a string, then the file gets generated how it used to be.
---
my_list: "['var1']"


This also happens when I try creating dictionaries and nested dictionaries. Any ideas on what could be causing this, or how I can fix it?

TIA,
Henry

Brian Coca

unread,
Aug 5, 2016, 8:48:35 AM8/5/16
to ansible...@googlegroups.com
This is a 'pythonism', in 2.0 we are much better about handling unicode, a consequence of that is that the structures that were possibly ASCII internally are now all unicode, which python represents as u''.

If you want a YAML or JSON output (without u' ') you should use |to_yaml or |to_json filters.


----------
Brian Coca

Henry Mendez

unread,
Aug 15, 2016, 2:38:23 PM8/15/16
to Ansible Project

On Friday, August 5, 2016 at 8:48:35 AM UTC-4, Brian Coca wrote:
This is a 'pythonism', in 2.0 we are much better about handling unicode, a consequence of that is that the structures that were possibly ASCII internally are now all unicode, which python represents as u''.

If you want a YAML or JSON output (without u' ') you should use |to_yaml or |to_json filters.


That works. Thank you! 
Reply all
Reply to author
Forward
0 new messages