Configuration Variables
Variables are used to define configuration parameters which can be applied to various entities. Such as Servers, Commands, Files, and File Templates.
Danger
Storing sensitive data (eg GitHub tokens) in variable values may expose that data in command preview and logs. Use Secrets for storing such data instead.
Access Rules
Group | Access Level |
---|---|
User | R: records with User group access level |
Manager | CRU: records with User or Manager group access level |
Root | CRUD: any record |
Info
Read+Write+Create+Delete stands for Read, Write, Create, Delete
Variable Configuration
Variables are located under the Cetmix Tower > Settings > Variables
menu.
Fields
Field | Description |
---|---|
Name | A readable name for the variable. |
Reference | A unique identifier for addressing the variable in conditions and expressions. Also used for YAML export/import. Leave blank to auto-generate based on the name. |
Access Level | Minimum access level required to access this Variable. |
Type | Variable type. |
Note | Additional notes or comments about the variable. |
Values | Values of the variable. Check Variable Applicability for more details. |
Variable Types
Type | Description |
---|---|
String | A string of characters. |
Selection | Pre-defined list of values. Name is displayed in the dropdown. Value is assigned as a variable value. |
Variable Applicability
Variables can be used in the following entities:
ls -lh {{ file_store_location }}`
url = "https://api.hetzner.cloud/"+{{ hetzner_api_version }}+"/servers"
- Files and File Templates:
FROM {{ os_image }}:{{ os_version }}
ARG ODOO_VERSION={{ odoo_default_version }}
- Other Variables:
Variable: Root Location
Value: /opt/cetmix_tower
Variable: Log File Location
Value: {{ root_location }}/logs
Variable Value Resolution Order
Variables values are rendered in the following order:
- If there is a variable value defined for a Server it will be used.
- If there is no variable value defined for a Server
Global
variable value will be used.Global
variable values are values without any Server selected.
Variable Value Rendering
Cetmix Tower uses jinja2
for variable rendering. This means that any jinja2
supported expressions can be used.
Here is an example of a command with if else
statements:
docker run -d -p {{ odoo_port }}:8069 \
{% if odoo_longpolling_port and odoo_longpolling_port != '0' and odoo_workers and odoo_workers != '0' %}
-p {{ odoo_longpolling_port }}:8072 \
{% endif %}
-v {{ odoo_data }}:/var/lib/odoo \
{% if odoo_config_location %}
-v {{ odoo_config_location }}:/etc/odoo \
{% endif %}
Variable Rendering Modes
There are two rendering modes available:
- Generic (or ssh) mode. This is the default mode. It is used for rendering variables in SSH Commands, Files and File Templates.
- Pythonic mode. This mode is used for rendering variables in Commands that run Python code.
Let use the following code as example:
current_branch={{ branch }}
current_version={{ package_version }}
need_update={{ update_available }}
where branch
is main
, package_version
is 0.12
and update_available
is False
Generic Mode
Default mode which renders variable values "as is". It is done in order to keep compatibility with any code interpreter which may be used to run a command. The code from example will be rendered the following way:
current_branch=main
current_version=0.12
need_update=False
Pythonic Mode
This mode is used in commands that run Python code (Action: Execute Python code
).
In this mode all variable values except Boolean and None are enclosed in double quotes.
The code from example will be rendered the following way:
current_branch="main"
current_version="0.12"
need_update=False
tower. System Variable
Special tower
variable can be used to access some system parameters and helper tools:
Server properties
tower.server.name
Current server nametower.server.reference
Current server referencetower.server.username
Current server SSH Usernametower.server.partner_name
Current server partner nametower.server.ipv4
Current server IPv4 Addresstower.server.ipv6
Current server IPv6 Addresstower.server.status
Current server statustower.server.os
Current server operating systemtower.server.url
Current server URL
Helper tools
tower.tools.uuid
Generates a random UUID4tower.tools.today
Current datetower.tools.now
Current date time
Warning
Do not redefine the tower
variable unless you really need that on purpose.