default

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, proceed with caution if you are using the same variable in multiple locations. Changing a default value can become a hassle, and it may be more efficient to define the variable with a default at the play or role level.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.174.174