What if a remote environment variable doesn't exist? Ansible take this as an fatal error. How to avoid that?

207 views
Skip to first unread message

Zhenkai Jiang

unread,
Sep 18, 2014, 5:53:55 AM9/18/14
to ansible...@googlegroups.com

I want to do some check using remote environment variables, which can be read from format like this

{{ ansible_env.NGINX_HOME }}

This "path" or environment variable can be absent, and that's the purpose of that check anyway.

But Ansible treat this as a fatal error, showing error message like

One or more undefined variables: 'dict object' has no attribute 'NGINX_HOME'

What can I do to just skip this?

Matt Martz

unread,
Sep 18, 2014, 8:03:19 AM9/18/14
to ansible...@googlegroups.com
You can use the |default jinja2 filter to help you out:

{{ ansible_env['NGINX_HOME']|default('') }}

This will default the value to '' if NGINX_HOME does not exist in the dict.

--
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/f58820d2-ed6f-4533-b3a7-2d57937949e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
ma...@sivel.net
http://sivel.net/

Zhenkai Jiang

unread,
Sep 18, 2014, 11:27:29 PM9/18/14
to ansible...@googlegroups.com
Thank you so much
Reply all
Reply to author
Forward
0 new messages