help avoiding u" prefixes on template generated output of a dictionary

5,344 views
Skip to first unread message

kesten broughton

unread,
Sep 24, 2014, 2:48:49 PM9/24/14
to ansible...@googlegroups.com

The goal is to define a dictionary like
 
dict1:
int1: 5
str1: "four"
 
and be able to template output the dictionary as a whole (not leaf by leaf) such that the output looks like
 
dict1: {"int1": 5, "srt1": "four"}
 
The actual output prefixes the values on the RHS of the : with a u so it looks like
dict1: {"int1": u"5", "srt1": u"four"}
 

dict1: {"int1": u"5", "srt1": u"four"}

Please see the gist for details.


Matt Martz

unread,
Sep 24, 2014, 2:54:47 PM9/24/14
to ansible...@googlegroups.com
You should probably use either the to_nice_yaml or to_yaml filters

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAK5UeTtD2jejt8%3DAqFsG2S-YCX3dmDgCw533F5LibW6OKMVRTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Michael DeHaan

unread,
Sep 24, 2014, 2:55:57 PM9/24/14
to ansible...@googlegroups.com
So that's just indicating unicode output, I'm curious if it's causing any specific problems for you?



Matt Martz

unread,
Sep 24, 2014, 2:58:44 PM9/24/14
to ansible...@googlegroups.com
An example being:

dict1: {{dict1|to_yaml}}

Which produces:

dict1: {_int1: '5', _str1: four}

Michael DeHaan

unread,
Sep 24, 2014, 3:00:06 PM9/24/14
to ansible...@googlegroups.com
Oh, nm, you mean templating the directionary.   Got it, there is also

{{ dict | to_nice_json }}

as well

Michael DeHaan

unread,
Sep 24, 2014, 3:00:24 PM9/24/14
to ansible...@googlegroups.com
Are those underscores before the names of the keys typos?



kesten broughton

unread,
Sep 25, 2014, 1:58:38 PM9/25/14
to ansible...@googlegroups.com
Thanks matt.  to_yaml worked great.

The underscores...
I use hash_behavior = merge and i've found that if i define parts of the dict across different files then a statement like

dict1: {{dict1}}

will fail with a "recursive definition detected" message.  I was being defensive.  In this case, it worked fine removing the underscores from the vars.

k
Reply all
Reply to author
Forward
0 new messages