Template language and variables#

Available since: version 6.1

The following variables are available to be used in “text” OS Template assets, with the “Advanced” template type. This mechanism replaces the old legacy template variables, which are now DEPRECATED. The new mechanism supports more advanced functionality such as conditionals, iterations etc.

Note that MetalSoft provides most of the templates already so their manual creation is not necessary in most situations. Refer to Managing OS templates for more details.

The template language uses the Nunjucks language which is a subset of “Jinjia2” language which is used by many solutions. Refer to the Nunjucks documentation for a complete reference of the language capabilities.

This template language is used currently only used for OS templates but will be implemented for Switch provisioning as well as Workflows.

Example usage#

The variables are accessed in blocks such as this one:

 {% for interface in network_configuration.interfaces. %}
    {% for address in interface.ipv4_addresses  %}
      address: {{address.ip}}
      netmask: {{address.netmask}}
      gateway: {{address.gateway}}
  {% endfor %}

For a real world example of this in action see This template.

You can also directly access variables using the full path for a simpler scenarios:

{{network_configuration.interfaces[0].ipv4_addresses[0].ip}}

Reference#

Refer to Template Variables Object Schema for a detailed description of the fields.

Example objects and their content#

The following are examples of objects and how they are populated.

---
resource_template_version: 0.5.0

######################################################################
datacenter:
  name: us-chi-qts01-dc
  dns_servers:
    - 8.8.8.8
    - 1.1.1.1
  ntp_servers:
    - 45.55.58.103
  web_proxy:
    server_ip: 192.168.20.80
    server_port: 3128
    username: test
    password: test

  repo_url_root: http://repo.test.com
  repo_url_root_quarantine_network: http://repo.test.com
  nfs_server: 122.183.184.6
  # The Windows KMS server hostname.
  kms: 192.168.20.100
  samba_server:
    samba_server_ip: 172.18.32.2
    # samba_server_hostname:  # omit the key if it has no value
    samba_server_password: bobspasswd
    samba_server_username: bob
    samba_server_windows_kit_share_name: mount
######################################################################

######################################################################
# User
user_ssh_key: []
user_custom_variables: []
######################################################################

######################################################################
# Cluster
management_ssh_key: test-key
######################################################################

######################################################################
# Infrastructure
infrastructure_id: 682
infrastructure_label: my-infrastructure
infrastructure_subdomain_permanent: infrastructure-682.us01.metalsoft.io
infrastructure_custom_variables: []
######################################################################

######################################################################
# Instance_array
instance_array_id: 1376
instance_array_label: instance-array-1376
instance_array_subdomain_permanent: instance-array-1376.us01.metalsoft.io
instance_array_custom_variables: []
# instance_array_firewall_managed: true
######################################################################

######################################################################
# Instance
instance_id: 20
instance_label: instance-22
instance_subdomain_permanent: instance-22.us01.metalsoft.io
instance_subdomain_base: us01.metalsoft.io
initial_username: ubuntu
initial_password: ChangeME-00
iscsi:
  initiator_iqn: iqn.1993-08.metalsoft.ausscbmubuntu02:init01
  chap_username: myuser
  chap_password: mypassword
instance_custom_variables: []
######################################################################

######################################################################
server:
  type: M.48.64.1
  serial_number: 78F7382
  disks:
    - id: 25
      size: 931
      vendor: dell
      serial_number: 6d0946605eb1fc002b983df42ef8b4d7
      # wwn: # omit the key if it has no value
      disk_type: logical_volume # ssd | hdd | nvme
    - id: 26
      model: HUS726020AL5211
      size: 1863
      vendor: HGST
      serial_number: 5000cca245039dc0
      # wwn: # omit the key if it has no value
      disk_type: ssd # hdd | nvme | logical_volume
  network_interfaces:
    - interface_index: 0
      protocol: ethernet
      capacity: 1    # Gbit/s
      mac_address: 6c:2b:59:81:27:25
    - interface_index: 1
      protocol: ethernet
      capacity: 1    # Gbit/s
      mac_address: 6c:2b:59:81:27:26
    - interface_index: 2
      protocol: ethernet
      capacity: 10    # Gbit/s
      mac_address: 6c:2b:59:81:20:70
    - interface_index: 3
      protocol: ethernet
      capacity: 10    # Gbit/s
      mac_address: 6c:2b:59:81:20:71
######################################################################

######################################################################
storage_configuration:
  # if not specified, the default is the first disk
  # one of the options ( id | size )
  install_disk:
    id: 26
    size: smallest # largest
    serial: 5000cca245039dc0
    path: /dev/sdb
  # the disk partition layout is per OS type
  layout: lvm # lvm | direct | custom
######################################################################

######################################################################
# Single WAN interface connected, single ip
network_configuration:
  interfaces:
    - network_type: wan
      network_id: 10
      network_label: wan
      interface_index: 0
      interface_type: physical
      type_interface_id: 0
      mac_address: 6c:2b:59:81:27:25
      dhcp4: false
      dhcp6: false
      # optional: false by default
      # Designate the connection as “critical to the system”, 
      # meaning that special care will be taken by to not release 
      # the assigned IP when the daemon is restarted.
      # critical: true
      mtu: 1500
      ipv4_addresses:
        - ip: 192.168.20.65
          cidr: 192.168.20.65/24
          netmask: 255.255.255.0
          mask_bits: 24
          gateway: 192.168.20.1
      routes:
        # - to: 0.0.0.0/0
        #   via: 192.168.20.1
        - to: 192.168.20.0/24
          via: 192.168.20.1
          # metric: 200
          on_link: true
          # table: 72
      dns_nameservers:
        addresses:
          - 8.8.8.8
          - 1.1.1.1
        search_domains: 
          - poc.metalsoft.io
######################################################################