The variables
Synopsis
- variable
A variable is an abstract black box (container) paired with an associated symbolic name, most often an option configuration, which contains some defined or undefined data setting referred to as a value.
- value
A value is a variable’s setting. Variable can have a default value, that is a setting defined in the structure file, or no value at all, then the value needs to be defined later by the operator.
Discussion
The variable is, by definition, strongly typed. Rougail uses static type definition and even type inference. Indeed, the constistency handling system heavyly relies on the type system definition. Variables may only be able to store a specified data type. OK, variables are the containers for storing the values. It has something to do with typing.
But consitency handling system is is not just about strong typing. It is more than that.
Names
It is with its name that we will be able to interact with the variable.
The name of a variable must be chosen carefully. It is the path that will allow users to retrieve their defined values. An obscure name will cause confusion.
By design, you cannot use just any character to name your variable.
The regular expression that validates our variable and family naming policy is:
re.compile(r"^[a-z0-9_]*$")
You can see that it is mandatory to only use lowercase ASCII letters, numbers and the "_" (undescore) character.
The snake case typographic convention is therefore used.
Attention
The name must not starts with _ character.
Parameters
Parameter |
Comments |
|---|---|
description
|
Description of the variable. User information to understand the usefulness of the variable. See also tutorial with a real world sample description parameter |
help
|
Additional help associated with the variable. See also tutorial with a real world sample help parameter |
mode
|
Variable’s mode. The mode is a way of classifying the importance, the level of expertise required, or the access rights to a variable. This parameter allows you to define the variable mode. Attention Mode is not configured by default. You have to define mode level before use this parameter. Default value: The
See also tutorial with a real world sample mode parameter |
tags
|
A tag allows you to specialize a variable. A tag can have several functions:
|
examples
|
List of examples to illustrate possible values for a variable See also tutorial with a real world sample examples parameter |
test
|
The Concretely, the content of this parameter is recorded in the |
type
|
Type of the variable. See the list of available type below. See also tutorial with a real world sample type parameter |
params
|
Parameters to adjust type validation of the variable. See the list of available parameters for each type below. See also tutorial with a real world sample params parameter |
multi
|
The value of the variable is a list. Default value: mostly
It possible to adjust multi parameters with params:
See also tutorial with a real world sample multi parameter |
validators
|
Value validators. The value of the variable will be considered invalid if the Jinja template return an error. See also tutorial with a real world sample validators parameter |
default |
Default value(s) of the variable. This value is typed, you must correctly fill out the YAML file to avoid defining a value with an incorrect type. For example, a For a non leading multiple variable, the first value defined in the list will also be the default value proposed if a new value is added to this variable. See also tutorial with a real world sample default parameter |
secret_manager |
The variable use a secret manager to get value .. todo:: document it |
auto_save
|
Variable with automatically modified value. A variable with automatically modified value is a variable whose value will be considered as modified (that is, it is no longer the variable’s default value). For example, if the value of this variable comes from a calculation, the value will no longer be recalculated. These variables are usually required variables. In fact, these variables are only automatically modified if they have a value. Default value: See also tutorial with a real world sample auto_save parameter |
mandatory
|
Mandatory variable. Variable whose value is For a multiple variable, this means that the list shall not be empty (means Default value: See also tutorial with a real world sample mandatory parameter |
empty
|
The value The If Default value: |
unique
|
The multiple variable accepts the same value several times. If unique is set to Default value: |
hidden
|
Invisible variable. Enables us to hide a variable. This means that the variable will no longer be visible in When a variable is made invisible, the user will not be able to modify its value; if he has already succeeded in modifying it, this value will not be taken into account. Default value: See also tutorial with a real world sample hidden parameter (the tutorial focuses on family, but the principle is the same for a variable) |
disabled
|
Disabled variable. Allows us to deactivate a variable. This means that the variable will no longer be visible to the user but also to a calculation. Default value: See also tutorial with a real world sample disabled parameter (the tutorial focuses on family, but the principle is the same for a variable) |
frozen
|
Read only variable. Enables us to have an immutable variable’s value. This means that the variable will be visible but user will not allowed to change the value. Default value: |
redefine
|
It is possible to define a variable in one structure file and change its behavior in a second structure file. In this case you must explicitly redefine the variable. Default value: |
exists
|
This parameter does two things:
Default value: |
choices calculation or a list of calculation or data |
Available choices. Important This parameter is only available for variable with |
regexp
|
Validation with a regular expressions. Important This parameter is only available for variable with |
Short-hand declaration
Short-hand declaration is a way to declare a variable in a condenced number of line.
To create a variable, just add a key with it’s name:
%YAML 1.2
---
version: 1.1
my_variable:
...
You can add a default value:
%YAML 1.2
---
version: 1.1
my_variable: my_value
...
Or a multi default value:
%YAML 1.2
---
version: 1.1
my_variable:
- my_value_1
- my_value_2
...
By default, the description of the variable is the variable name. It’s a good practice to describe a variable. Just add comment in same line of name, this comment is used as description:
%YAML 1.2
---
version: 1.1
my_variable: my_value # This is a great variable
...
But in short-hand notation, you can only define variable name, default value, multi and description.
Attention
Any other parameters will create extra variables or families
Variable’s types
A variable always has a type. The system is strongly typed.
Depending on the definition of the variable type, the defined variable will accept values of the associated type.
Primitive Types
Value |
Comments |
Parameters |
Samples |
|---|---|---|---|
string |
character string (default type) |
example “1” “true” |
|
integer |
a integer |
|
42 |
float |
a floating number |
1.42 |
|
boolean |
A boolean, if no value is defined the default value of this variable will be See also tutorial with a real world sample boolean type variable |
|
Specialized type
Value |
Comments |
Parameters |
Samples |
|---|---|---|---|
secret |
a secret (like a password, a private key, etc.) See also tutorial with a real world sample secret type variable |
|
|
a mail address |
|||
unix_filename |
a file name in the Unix meaning |
|
|
date |
a date in the format |
|
|
unix_user |
a user in the Unix meaning See also tutorial with a real world sample unix type variable |
test |
|
ip |
any kind of IPv4 address |
|
|
netmask |
mask of an IPv4 address |
|
|
network |
network address |
|
|
broadcast |
broadcast address |
|
|
domainname |
domain name |
See also tutorial with a real world sample domainname type variable or a more complet domainname type variable |
|
web_address |
web address |
See also tutorial with a real world sample web_address type variable |
|
port |
port |
See also tutorial with a real world sample port type variable |
8080 |
mac |
MAC address |
11:11:11:11:11:11 |
|
unix_permissions |
access rights to the file, directory, etc. |
644 |
|
choice |
available choices See also tutorial with a real world sample choice type variable |
||
regexp |
Validation with a regular expressions See also tutorial with a real world sample regexp type variable |
r”^#(?:[0-9a-f]{3}){1,2}$” |
Default type
If the type parameter is not set, Rougail has to define a logical type to valid correctly values:
if
choicesorregexpparameter is set, Rougail will set thechoiceorregexptype
See also
tutorial with a real world sample choice deducted type or regexp deducted type
if a default value is define, Rougail will infers default value type and set a primitive type to the variable
See also
tutorial with a real world sample type inference
if a variable calculation is define as default value, Rougail copy the type
See also
tutorial with a real world sample type copying
the default type is
string