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 ...
sshd_config_test_config: "{{ __sshd_config_test_config|default(None)}} "
{% 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.
thanks
Peter