Jinja templating
Jinja templating is applicable within specific sections of the Squest configuration. For example, Jinja templating enables the prefilling of a survey field for a day 2 operation using the specs of the instance.
Jinja templating usage with {{ instance }}
as context:
Jinja templating usage with {{ request }}
as context:
- Operation job template config (inventory, credentials, tags, limit)
- Approval workflow step
Jinja templating usage with {{ user }}
as context:
Examples
String with no jinja
Even if the context is sent, a hard coded string can be used without using it.
Jinja string | My hard coded value |
Result | My hard coded value |
Using the instance as context
Accessing instance name:
Instance context |
|
Jinja string | My hard coded value with {{ instance.name }} |
Result | My hard coded value with my_instance |
Accessing instance spec:
Instance context |
|
Jinja string | {{ instance.spec.os }} |
Result | linux |
Note
The spec
and user_spec
variables are only usable on Update or Delete operations as the pending instance does not contain any spec before its provisioning.
Note
If the given variable key doesn't exist, the default value will be set to an empty string.
Using the request as context
This example, used in the "default limit" of the operation job template config, allows to automatically configure the inventory limit following the given "dns" field of the survey.
Instance context |
|
Jinja string | {{ request.fill_in_survey.dns }} |
Result | vm-name.domain.com |
Dict access
Instance JSON spec |
|
Jinja string | {{ instance.spec.os['linux'] }} |
Result | ubuntu |
List access
Instance JSON spec |
|
Jinja string | {{ spec.os[1] }} |
Result | windows |
Filters
Jinja filters can also be used to transform variables.
For example, the 'select multiple' field type requires a list of string separated with a carriage return marker (\n
).
Instance JSON spec |
|
Jinja string | {{ spec.os | join('\n') }} |
Result | linux\nwindows |
Conditions
In this example, the target inventory ID is changed following a survey variable is_prod
.
Instance JSON spec |
|
Jinja string | {% if is_prod %}1{% else %}3{% endif %} |
Result | linux\nwindows |