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

Working with Constants

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

Perform the following steps to create and reference constants:

  1. Click in the inventory file, then create a consts section.
  2. Define your constants in the consts section.
  3. In the vars section, go to the variable from which you want to reference one (or more) constants.
  4. Insert the reference. Use this format: ${const://constantVariableName}
  5. Repeat the previous two steps for other variables, if needed.

For example references, see the next code block:

Constants

consts:
c1: nevis.net
c2: nevis
c3: 8080
c4: true
c5: secret://cd445cb0e611e26f8f6480c2

vars:
var1: ${const://c1} # resolved: nevis.net
var2: http://${const://c1}:${const://c3} # resolved: http://nevis.net:8080
var3: https://${const://notfound} # resolved: https://${const://notfound}
var4: ${const://c3} # resolved: 8080 (note: 8080 as a number, not as a string)
var5: ${const://c4} # resolved: true (note: true as a boolean, not as a string)
var6:
varKey: ${const://c2} # resolved: nevis
var7:
- ${const://c1} # resolved: [ nevis.net, portal.nevis.com ]
- portal.nevis.com
var8: ${const://c5} # resolved: secret://cd445cb0e611e26f8f6480c2

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

How to create and reference constants