March 2019
Intermediate to advanced
412 pages
9h 49m
English
The default filter is a way to provide a default value for an otherwise undefined variable, which will prevent Ansible from generating an error. It is shorthand for a complex if statement, checking if a variable is defined before trying to use it with an else clause to provide a different value. Let's look at two examples that render the same thing. One uses the if/else structure, while the other uses the default filter:
{% if some_variable is defined -%}
{{ some_variable }}
{% else -%}
default_value
{% endif -%}{{ some_variable | default('default_value') }}
The rendered result of each of these examples is the same; however, the example using the default filter is much quicker to write and easier to read.
While default is very useful, ...
Read now
Unlock full access