Skip to main content
Version: 7.2405.x.x LTS

Working with Constants

Overview

If you want to use a specific value inside multiple variables in an inventory, you can use constants (consts). For this, first create a constant and refer to it from the variables inside your inventory. If you change the value of the constant, the change applies to all variables that refer to the given constant.

The constants can be local or global.

  • Local constants are created and used only in one inventory.
  • Global constants are created in a dedicated Global Constants screen and used in multiple inventories.
note

Similarly to global secrets, the value of the global constants cannot be exported or published in the inventory. Only the reference to the constant is part of the inventory after exporting or publishing the inventory.

Use local constants

Perform the following steps to create and reference local constants:

  1. Click in the inventory file, then create a consts section.
  2. Define your constants in the consts section.
  3. Insert the reference of the constant where you want to use it. If your constant is called myConst, the reference will be ${const://myConst}
note

Constants can not reference each other.

For example references, see the next code block:

Constants

schemaVersion: 1

consts:
connection_user: nvbuser
connection_port: 5222
connection_password: secret://0b3cf3cafcf43e25f35f8f40
siven_001: srv_001.siven.ch
proxy-bind-address:
- http://0.0.0.0:80
- https://0.0.0.0:443

hosts:
- srv_001.siven.ch:
vars:
__connection_user: ${const://connection_user}
__connection_port: ${const://connection_port} # note: 5222 will be substituted here as a number, not as a string
__connection_password: ${const://connection_password}
- srv_002.siven.ch:
vars:
__connection_user: ${const://connection_user}
__connection_port: ${const://connection_port}
__connection_password: ${const://connection_password}
proxy-host-name:
- http://srv_001.siven.ch:${const://connection_port}

groups:
- proxy:
members: [ srv_001.siven.ch, srv_002.siven.ch ]
vars:
proxy-bind-address: ${const://proxy-bind-address}

vars:
virtual-host-frontend-addresses:
- http://${const://siven_001}:8080
- https://${const://siven_001}:443

The following movie shows you how to create and reference constants:

How to create and reference constants

Global constants

You can create and manage global constants in the Global Constants screen. For details, see the Global Tenant Constants chapter.

Global constants are used by placing their references into inventories. You can do this in the following ways:

  • Copy-paste the reference ID into the inventory:

    1. Open the Global Constants screen.
    2. Click the copy icon next to the constant name in the constants table to copy its reference to the clipboard.
    3. Open the Inventory Editor.
    4. Paste the copied reference in your inventory.
  • Use the Insert global constant button in the Inventory Editor:

    1. Place the caret where you want to reference a global constant
    2. Click the Insert global constant button.
    3. Select the global constant from the dropdown and click Insert.
  • Type the reference ID into the inventory. Use the following format: ${g-const://constantName}. Here, constantName is the name of the constant as given during creation.

The following movies show the process of using global constants in your variables:

How to refer to a global constant in a variable by copy-pasting the referenceHow to refer to a global constant in a variable by using the Insert global constant buttonHow to refer to a global constant in a variable by manually typing it