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.

        thanks
                Peter
-- 
*Peter Hudec*
Infraštruktúrny architekt
phu...@cnc.sk <mailto:phu...@cnc.sk>

*CNC, a.s.*
Borská 6, 841 04 Bratislava
Recepcia: +421 2  35 000 100

Mobil:+421 905 997 203
*www.cnc.sk* <http:///www.cnc.sk>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4eb9e64e-de0a-e363-9c7f-cc249eb04e29%40cnc.sk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to