Manifest preprocessor
We’ve created a simple manifest file in the previous step. We’ll explore each of the fields in detail in the following sections but before we go any further, let’s explore the format.
At first glance, it might seem like a normal YAML file but before it is parsed, it is transformed through the pmesh preprocessor, LYML
(Lua YAML).
This allows us to use Lua code in the YAML file to define conditions, loops, and other control structures.
You can preview the transformed YAML file by running pmesh preview [file]
in the terminal.
The locals block $
The locals
block is used to define variables that can be used throughout the manifest file.
This is useful for defining common values that are used in multiple places.
It should be placed at the top of the node for clarity and is named $
.
The $(...)
syntax is used to evaluate the expression inside the brackets and replace it with the result.
You can also replace this entire block with a Lua script by making it a multiline string literal like so:
Globals
You might have noticed the $(HOST)
variable.
we have a special set of variables that we can use in the manifest file, which are:
HOST
- The hostname of the machineMACH
- The machine IDIMACH
- The machine ID as an integerOS
- The operating systemARCH
- The architecturePID
- The process IDPPID
- The parent process IDUSER
- The user IDCPU
- The number of CPUsRAM
- The total RAMargs
- The command line argumentsmatch
- A function to match a string with a regular expressionglob
- A function to match a pattern with a globparse
- A function to parse a filefetch
- A function to fetch a URLenv
- A table of environment variablesud
- The peer user data (A set of key-value pairs shared with all the machines to tag this node, can be set viapmesh set peer-ud [key] [value]
)localud
- The local user data (A private set of key-value pairs to use in this machine, can be set viapmesh set local-ud [key] [value]
)
Conditional Blocks - ${cc}
and ${cc}:
If the ${...}
syntax is used in a list, or in a key-value pair that starts another key-value pair, it is treated as a conditional block
and the expression inside the brackets is evaluated to determine if rest should be mixed in or not.
Switch Blocks ${match ...}:
The ${match ...}
syntax is used to define a switch block, which match the string value of the expression against the cases interpreted as regular expressions.
Loop Blocks ${each ...}
The ${each ...}
syntax is used to define a loop block, which iterates over the array or table and mixes in the rest of the block for each element.
It can be used in any of the following forms:
${each table}
- Iterates over the table without any locals${each table as key}
- Iterates over the keys of the table${each table as key, value}
- Iterates over the key-value pairs of the table
Import directive $import
You can import other files into the manifest file using the $import: "file"
syntax which will be mixed in similar to other blocks.
- this.yml
Directoryhi
- a.yml # Contains
a: 1
- b.yml # Contains
b: 2
- a.yml # Contains