calcuation and dynamic family

This commit is contained in:
gwen 2025-09-18 17:17:02 +02:00
parent 91112a905a
commit 6b6aeceb6e
2 changed files with 107 additions and 1 deletions

View file

@ -143,9 +143,113 @@ Deactivating a family means that we will not be able to access it as well as the
we are using Jinja in a classical way, that is, Jinja allows us to handle different cases, we are using Jinja in a classical way, that is, Jinja allows us to handle different cases,
for example with the `if` statement. for example with the `if` statement.
What can be calculated?
---------------------------
We have seen that the `disabled` or `hidden` properties could be calculated.
The default values can be calculated too.
.. todo:: montrer un exemple de valeur par défaut calculées (type jinja)
.. 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
-----------------------------------------------
Let's come back to the previous section's :ref:`dynamic family example <conditional_hidden_family>`\ .
In a dynamic family, as seen before, you have the possibility to name your identifier. In the classic declaration,
the identifier's variable is named "identifier" by default. Sounds logical:
.. code-block:: yaml
"{{ identifier }}_proxy":
description: "{{ identifier }} Proxy"
dynamic:
- HTTPS
- SOCKS
dynamic:
- HTTPS
- SOCKS
Here the identifer's variable takes the value of the `dynamic` family parameter.
We have another possibility:
.. 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
..
manual:
use_for_https:
description: Also use this proxy for HTTPS
default: true
"{{ identifier }}_proxy":
description: "{{ identifier }} Proxy"
dynamic:
- HTTPS
- SOCKS
hidden:
jinja: |
{% if my_identifier == 'HTTPS' and manual.use_for_https %}
HTTPS is same has HTTP
{% endif %}
params:
my_identifier:
type: identifier
description: |
in HTTPS case if "manual.use_for_https" is set to True
address:
description: "{{ identifier }} address"
default:
variable: manual.http_proxy.address
port:
description: "{{ identifier }} port"
default:
variable: manual.http_proxy.port
version:
description: SOCKS host version used by proxy
choices:
- v4
- v5
default: v5
disabled:
type: identifier
when: 'HTTPS'
Here in the `hidden` property we have the possibility to name an identifier:
.. code-block:: yaml
params:
my_identifier:
type: identifier
Here, the identifer is named `my_identifier`, in a jinja calculation:
.. code-block:: yaml
hidden:
jinja: |
{% if my_identifier == 'HTTPS' and manual.use_for_https %}
HTTPS is same has HTTP
{% endif %}
params:
my_identifier:
type: identifier
description: |
in HTTPS case if "manual.use_for_https" is set to True
.. keypoints:: Key points .. keypoints:: Key points
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`.

View file

@ -185,6 +185,9 @@ We can see that the dynamic family has created:
as we wanted, containing an address and a port. as we wanted, containing an address and a port.
.. _conditional_hidden_family:
A conditional hidden familiy A conditional hidden familiy
-------------------------------- --------------------------------
@ -243,7 +246,6 @@ it uses `use_for_https` variable:
description: Also use this proxy for HTTPS description: Also use this proxy for HTTPS
default: true default: true
.. keypoints:: Key points .. keypoints:: Key points
- We now know what a generic family is, with its identifier. - We now know what a generic family is, with its identifier.