Docs
Reference

Variables

Declaring variables, computing them, and passing them to the designs a design uses.

Declaring variables

Every design has a variables mapping, {} when it takes none. Each entry is one of:

ValueMeans
$USERRequired. The deploy page asks for it, and planning without it is refused
$USER_OPTIONALOptional. When you don't give it, every field that uses it is left out, as if its line weren't there
A value, such as active or 42A default. The deploy page doesn't ask for it
An expression, such as '{{ variables.site_name | slugify }}'Computed when the design renders, from other variables

A computed variable can use the same filters and arithmetic as a field. See Expressions and loops.

Using variables

{{ variables.<name> }} is the variable's value. An expression that names a variable the design doesn't declare refuses the render, naming the object and field.

Passing variables to the designs you use

An item with design: nbd:<catalogue name> includes another design. Its template_vars mapping sets that design's variables:

devices:
- design: nbd:devices/Dell_R640_w_module
  template_vars:
    name: '{{ variables.rack_name }}-COMPUTE-01'
    position: 1
    site: '{{ parent.site }}'
    rack: '{{ parent }}'
  • Each value is worked out in the including design: variables, parent and loop are the including design's.
  • The included design's required variables must all be given, and its optional ones may be.
  • Its defaults apply to whatever template_vars leaves out, and its computed variables are worked out for each inclusion, so ten included servers each compute their own.
  • Values pass one level down. A design two levels down gets only what the design that includes it passes on.

On this page