# jinja2 default fiter set to None

**URL:** <https://forum.ansible.com/t/jinja2-default-fiter-set-to-none/25784>\
**Category:** Ansible Project\
**Created:** [October 19, 2017, 10:28pm UTC](https://forum.ansible.com/t/jinja2-default-fiter-set-to-none/25784 "2017-10-19T22:28:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [October 19, 2017, 10:28pm UTC](https://forum.ansible.com/t/jinja2-default-fiter-set-to-none/25784/1 "2017-10-19T22:28:05Z")

</div>

Hi,

is there any way how to set undefined variable to None /python/, null  
/yaml/ value ?

The filter default sets it always to empty string ... Consider this in  
defaults and emplate file ...

```defaults
sshd_config_test_config: "{{ __sshd_config_test_config|default(None)}} "

```

```template
{% macro print_scalar(item_name, item_value=None, ident=0,
comment=False) -%}
{% if item_value is not none %}
{{"\t" * ident}}{{ item_name }} {{ item_value }}
{%- elif comment %}
{{"\t" * ident}}# {{ item_name }}
{%- endif %}
{%- endmacro %}

{{ print_scalar('test_config', sshd_config_test_config, 0, True) }}

```

This will print config value with an empty string, the jinja2 template  
does is when \_\_sshd\_config\_test\_config is not defined.

if \_\_sshd\_config\_test\_config is set to value or null, it works as  
expected. This varialble is OS based and included in os-{{  
ansible-os-family}}.yml.

I'm trying to avoid type all variables into all os specific files.

&nbsp;&nbsp;thanks  
&nbsp;&nbsp;&nbsp;&nbsp;Peter
