jinja2 template default not working when variable is not defined

134 views
Skip to first unread message

jepper

unread,
Jan 4, 2016, 8:45:39 AM1/4/16
to Ansible Project
Hello all, please can someone help me explain why this jinja2 template fail if I have not defined wildfly_memory_settings ?

JAVA_OPTS="-Xms{{ wildfly_memory_settings.Xms | default('64m') }}  -Xmx{{ wildfly_memory_settings.Xmx | default('512m') }} -XX:MaxPermSize=256m -verbose:gc -Djava.net.preferIPv4Stack=true"

The error: fatal: [targetbox] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'wildfly_memory_settings' is undefined", 'failed': True}

David Karban

unread,
Jan 4, 2016, 8:52:42 AM1/4/16
to ansible...@googlegroups.com
Hi, 

it is because to test wildfly_memory_settings.Xms you need to access wildfly_memory_settings first and it is not defined. Unfortunatellz zou cannot use defautl this way.

David
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu

--
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/5ec331ce-6ac2-4c88-8281-39fe1499b570%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Jan 4, 2016, 9:00:10 AM1/4/16
to Ansible Project
default only works on the 'last' var, so if you have to default the
main var also if that can be undefined.

{{ (wildfly_memory_settings|default({})).Xms | default('64m') }}

--
Brian Coca

rektide

unread,
Jan 4, 2016, 5:00:31 PM1/4/16
to ansible...@googlegroups.com
This might work?

-Xms{{ (wildfly_memory_settings|default({'Xms': '64m'})).Xms }}

And if not, this ought:

-Xms{{ wildfly_memory_settings.Xms if wildfly_memory_settings is defined
else '64m' }}
Reply all
Reply to author
Forward
0 new messages