Basic Inventory Example
This example illustrates key aspects of the configuration generation system Templating Generation.
Define a playbook with a
CSV_INVENTORYtask to generate configuration files from each CSV row.Use a
variables.osppfile to supply default playbook variables, which can be overridden at task level.Apply path providers (
CELL_PICKER,RELATIVE,EVALUATION) to construct output paths dynamically.Execute the playbook via the Composer interface and verify the generated output in OnSphere.
git checkout origin/osp-web-configuration .
git checkout origin/example-template-gen-playbook-inventory .
Prerequisites
Steps
1. File Creation
templates/inventory/basic-inventory
# Metadata : 28.05.2025
destination;location;n_labels;destination_opt
root/;fribourg;1;
root/;lausanne;2;root/dashboard/lausanne/
templates/variables/test.variables
{
"dashboard_basename": "from-playbook-variables-files"
}
The first step generally consists in setting up a playbook. This defines the entry point of the configuration logic. Execution typically occurs through the template.execute command. If more than one environment is available, an environment selector will prompt accordingly.
Hint
The templates directory remains ignored by both the validator and the dispatcher.
templates/playbooks/inventory.playbook
{
"priority": 0,
"environments": [
{
"variables": {
"variablesFiles": [
{
"relativePath" : "templates/variables/test.variables"
}
],
"local": [
{
"key": "dashboard_basename",
"value": "from-playbook-variables"
}
]
},
"names": ["test"],
"tasks": [
{
"type": "CSV_INVENTORY",
"sourceInventory": "templates/inventory/basic-inventory.csv",
"headerLine": 2,
"startingLine": 3,
"rules": [
{
"source": {
"relativePath": "templates/sources/dashboard_one_label",
"type": "RELATIVE"
},
"destination": {
"type": "EVALUATION",
"evaluation": "root/dashboard/{{location}}"
},
"condition": {
"evaluation": "n_labels == 1",
"type": "JEXL_EVALUATION"
}
},
{
"source": {
"relativePath": "templates/sources/dashboard_two_label/",
"type": "RELATIVE"
},
"destination": {
"type": "CELL_PICKER",
"column": 3
},
"condition": {
"evaluation": "n_labels == 2",
"type": "JEXL_EVALUATION"
}
}
],
"variables": {
"local": [
{
"key": "dashboard_basename",
"value": "from-rules"
}
]
}
}
]
}
]
}
Variables
The playbook introduces a variable named dashboard_basename. It is initially defined in:
templates/variables/test.variables
{
"dashboard_basename": "from-playbook-variables-files"
}
According to Variable Evaluation Order, variables from variablesFiles may be overridden by values inside the playbook. As a result:
{
"key": "dashboard_basename",
"value": "from-playbook-variables"
}
This value is later replaced again at task evaluation, resulting in:
{
"key": "dashboard_basename",
"value": "from-rules"
}
Task Definition
A single task is declared in the playbook. This task is of type CSV_INVENTORY, meaning that each row of a CSV inventory is interpreted, and rules are applied accordingly.
Such a pattern provides contextual file generation based on row-level logic.
Rules
Rules define behavior per row. In this example, conditions are based on the value of labels, executing logic only when it matches specific criteria (e.g., 1 or 2 labels).
Path Provider
Path generation is handled by different strategies:
CELL_PICKER: Extracts values directly from CSV cells
RELATIVE: Uses a static relative reference (e.g., templates/root)
EVALUATION: Constructs paths dynamically using Nunjucks expressions
2. Composer Execution
The Composer interface allows execution of commands like:
3. Commit & Push
git add .
git commit -m "Push simple template example"
git push
4. Onsphere Verification
Once the generation is complete, OnSphere can be used to validate the output. In this example, Lausanne and Fribourg offer a comparison point—Lausanne renders with two labels, while Fribourg displays only one.