jinja calculation
This commit is contained in:
parent
6b6aeceb6e
commit
6505ac9ab9
2 changed files with 58 additions and 6 deletions
|
|
@ -153,7 +153,6 @@ The default values can be calculated too.
|
||||||
|
|
||||||
.. todo:: montrer aussi ici des exemples de calculs de valeurs variables, ce qui est un des usages principaux de jinja
|
.. todo:: montrer aussi ici des exemples de calculs de valeurs variables, ce qui est un des usages principaux de jinja
|
||||||
|
|
||||||
|
|
||||||
Using jinja in a dynamic family declaration
|
Using jinja in a dynamic family declaration
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
|
|
||||||
|
|
@ -173,10 +172,11 @@ the identifier's variable is named "identifier" by default. Sounds logical:
|
||||||
- HTTPS
|
- HTTPS
|
||||||
- SOCKS
|
- SOCKS
|
||||||
|
|
||||||
|
|
||||||
Here the identifer's variable takes the value of the `dynamic` family parameter.
|
Here the identifer's variable takes the value of the `dynamic` family parameter.
|
||||||
|
|
||||||
We have another possibility:
|
.. type-along:: Using a jinja calculation with a parameter
|
||||||
|
|
||||||
|
We have the possibility to use a given variable variable inside a jinja calculation:
|
||||||
|
|
||||||
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_050/firefox/20-manual.yml
|
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_050/firefox/20-manual.yml
|
||||||
:language: yaml
|
:language: yaml
|
||||||
|
|
@ -225,7 +225,9 @@ We have another possibility:
|
||||||
type: identifier
|
type: identifier
|
||||||
when: 'HTTPS'
|
when: 'HTTPS'
|
||||||
|
|
||||||
Here in the `hidden` property we have the possibility to name an identifier:
|
This can be done by defining a `my_identifier` variable.
|
||||||
|
|
||||||
|
This jinja variable comes from the `params` parameter of the `hidden` property.
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
|
@ -233,7 +235,8 @@ Here in the `hidden` property we have the possibility to name an identifier:
|
||||||
my_identifier:
|
my_identifier:
|
||||||
type: identifier
|
type: identifier
|
||||||
|
|
||||||
Here, the identifer is named `my_identifier`, in a jinja calculation:
|
Here the `hidden` property's value is defined by a jinja calculation.
|
||||||
|
In this jinja calculation we have a `my_identifier` jinja variable.
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
|
@ -248,11 +251,60 @@ Here, the identifer is named `my_identifier`, in a jinja calculation:
|
||||||
description: |
|
description: |
|
||||||
in HTTPS case if "manual.use_for_https" is set to True
|
in HTTPS case if "manual.use_for_https" is set to True
|
||||||
|
|
||||||
|
.. type-along:: The `when` and `when_not` parameter notation
|
||||||
|
|
||||||
|
Handling the SOCKS version
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Now we need to handle the SOKS version as show in the firefox configuration screenshot:
|
||||||
|
|
||||||
|
.. image:: images/firefox_soks_version.png
|
||||||
|
|
||||||
|
|
||||||
|
We'll just add a choice variable with a default value and a disabled property:
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
version:
|
||||||
|
description: SOCKS host version used by proxy
|
||||||
|
choices:
|
||||||
|
- v4
|
||||||
|
- v5
|
||||||
|
default: v5
|
||||||
|
disabled:
|
||||||
|
type: identifier
|
||||||
|
when: 'HTTPS'
|
||||||
|
|
||||||
|
There is still something new about this YAML, though. It is the `when` parameter
|
||||||
|
of the `disabled` property. You have two possible notations: `when` or `when_not`.
|
||||||
|
These two notations are just a short hand of what we could express in jinja as
|
||||||
|
this code:
|
||||||
|
|
||||||
|
.. code-block:: jinja
|
||||||
|
|
||||||
|
{% if identifier == 'HTTPS' %}
|
||||||
|
when the identifer equals 'HTTPS' then the SOCKS version is disabled
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
And the `when_not` parameter is just the logical opposite.
|
||||||
|
|
||||||
|
Here is the final version of our YAML dynamic family:
|
||||||
|
|
||||||
|
.. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_050/firefox/20-manual.yml
|
||||||
|
:language: yaml
|
||||||
|
:caption: firefox/20-proxy.yml
|
||||||
|
|
||||||
|
|
||||||
.. keypoints:: Key points
|
.. keypoints:: Key points
|
||||||
|
|
||||||
|
**keywords**
|
||||||
|
|
||||||
|
- calculation with a jinja type calculation
|
||||||
|
- calculation with a `when` or `when_not` parameter
|
||||||
|
- defining a jinja internal variable in a jinja calculation
|
||||||
|
|
||||||
|
**progress**
|
||||||
|
|
||||||
Here we have come to the possibility of making any kind of calculations based on the state of the :term:`configuration`.
|
Here we have come to the possibility of making any kind of calculations based on the state of the :term:`configuration`.
|
||||||
This is an important feature to manage the stateful aspect of a configuration.
|
This is an important feature to manage the stateful aspect of a configuration.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
BIN
docs/tutorial/images/firefox_soks_version.png
Normal file
BIN
docs/tutorial/images/firefox_soks_version.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 118 KiB |
Loading…
Reference in a new issue