# Nested varibbles and defined

**URL:** <https://forum.ansible.com/t/nested-varibbles-and-defined/21721>\
**Category:** Ansible Project\
**Created:** [June 9, 2016, 12:33pm UTC](https://forum.ansible.com/t/nested-varibbles-and-defined/21721 "2016-06-09T12:33:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pedro\_Barbosa](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@Pedro\_Barbosa](https://forum.ansible.com/u/Pedro_Barbosa)\
**Post date:** [June 9, 2016, 12:33pm UTC](https://forum.ansible.com/t/nested-varibbles-and-defined/21721/1 "2016-06-09T12:33:04Z")

</div>

Hi. Right now `defined` only works with up-to-second-last defined variables. That is, if var1 exists as a map but var1.var2 doesn’t, this works and will print DEFAULTED: `var1.var2 | default('DEFAULTED')`. But for the same var1 this results in an error: `var1.var2.var3 | default('FAILS')`.

So I was reading the docs how to either pass extra params to default to allow to check/early return over null variables (like the var1.var2 above) or write a new function/jinja2 filter that allows that.

So far I was not able to do it. All I could google was actions/lookup/callback/vars plugins. Any ideas on this is ver welcome!

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 15, 2016, 11:29pm UTC](https://forum.ansible.com/t/nested-varibbles-and-defined/21721/2 "2016-06-15T23:29:30Z")

</div>

need to set default at every level that might be undefined.

(var1|default({})).(var2|default({})).var3 | default(‘FAILS’)
