You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'netlab config' used to pass the '-e' parameter to the Ansible
playbook. That approach no longer works after we started rendering the
Jinja2 templates in netlab.
This commit parses '-e' parameters in 'netlab config' command and adds
extra variables to node data, making them available in custom config
templates.
Other minor fixes:
* Refactor common Ansible args processing into shared functions
* Check that no extra vars are specified on config reload
* Remove an unneeded call to set_custom_config
Copy file name to clipboardExpand all lines: docs/netlab/config.md
+36-11Lines changed: 36 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,16 @@
1
1
(netlab-config)=
2
2
# Deploying Custom Device Configurations
3
3
4
-
**netlab config**uses an internal Ansible playbook (`netsim/ansible/config.ansible`) to deploy custom device configurations generated from the supplied Jinja2 template(s) to lab devices. It takes lab parameters from the _netlab_ snapshot file and Ansible inventory created by the **[netlab create](netlab-create)** or **[netlab up](netlab-up)** command.
4
+
**netlab config**is used to deploy custom device configuration templates to lab devices. It reads lab parameters from the _netlab_ snapshot file created by the **[netlab create](netlab-create)** or **[netlab up](netlab-up)** command, renders the supplied Jinja2 template ([limitations](dev-templates)), and uses the internal `config.ansible` Ansible playbook to deploy the rendered configuration snippets.
5
5
6
-
You have to use **netlab config** on a running lab. If you want to try out the configuration templates without starting the lab, add the [**config** attribute](custom-config) to node data and run **netlab create** (to create the Ansible inventory) followed by **[netlab initial -c -o](netlab-initial)** to create the configuration files.
6
+
You have to use **netlab config** on a running lab. If you want to try out the configuration templates without starting the lab, add the [**config** attribute](custom-config) to node data and run **netlab create** (to generate the snapshot file), followed by **[netlab initial -c -o](netlab-initial)** to create the configuration files.
-l, --limit LIMIT Limit the operation to a subset of nodes
24
+
-e, --extra-vars EXTRA_VARS [EXTRA_VARS ...]
25
+
Specify extra variables for the configuration template
21
26
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
22
27
-q, --quiet Report only major errors
23
-
-i INSTANCE, --instance INSTANCE
24
-
Specify lab instance to configure
28
+
-i, --instance INSTANCE
29
+
Specify the lab instance to configure
25
30
26
31
All other arguments are passed directly to ansible-playbook
27
32
```
@@ -40,19 +45,39 @@ When executed with the `-i` option, **netlab config** expects the configurati
40
45
41
46
## Limiting the Scope of Configuration Deployments
42
47
43
-
All unrecognized parameters are passed to the internal `config.ansible` Ansible playbook. You can use **ansible-playbook** CLI parameters to modify the configuration deployment, for example:
48
+
You can use the `-l` parameter to deploy device configurations on a subset of devices. The parameter value must be a valid _netlab_ node selection expression ([more details](netlab-inspect-node)).
44
49
45
-
*`-l` parameter to deploy device configurations on a subset of devices.
46
-
*`-C` parameter to run the Ansible playbook in dry-run mode.
50
+
All unrecognized parameters are passed to the internal `config.ansible` Ansible playbook, allowing you to use the **ansible-playbook** CLI parameters to modify the configuration deployment. For example, you can use the `-C` parameter to run the Ansible playbook in dry-run mode.
51
+
52
+
## Extra Variables
53
+
54
+
You can use the `-e` parameter to specify an extra variable value in the `name=value` format (the `-e` parameter can be used multiple times). _netlab_ recognizes only the `name=value` format, not the JSON or filename formats recognized by Ansible.
55
+
56
+
The extra variables are applied to all nodes and can be used in device configuration templates. For example, the following Jinja2 template uses the `df_state` variable to turn BGP default route advertisements on or off:
After saving the above template into `bgp_default.j2`, you can use `netlab config bgp_default --limit somenode` to enable BGP default route advertisement and `netlab config bgp_default --limit somenode -e df_state=off` to turn it off.
47
72
48
73
## Restoring Saved Device Configurations
49
74
50
-
**netlab config --reload** implements the *reload saved device configurations* part of the **netlab initial -r** command. It waits for devices to become ready (because it's used immediately after a lab has been started) and starts the initial configuration process on devices that need more than a replay of saved configuration ([more details](netlab-up-reload)).
75
+
**netlab config --reload** implements the *reload saved device configurations* part of the **netlab initial -r** command. It waits for devices to become ready (since it's used immediately after a lab has been started) and starts the initial configuration process on devices that need more than a replay of saved configuration ([more details](netlab-up-reload)).
51
76
52
-
After that, it treats the saved device configurations as custom templates and uses the same process as the regular **netlab config** command.
77
+
After that, it treats the saved device configurations as custom templates (using the same process as the regular **netlab config** command), allowing you to use Jinja2 expressions in saved device configurations.
53
78
54
79
## Debugging Device Configurations
55
80
56
81
To display device configurations within the Ansible playbook without deploying them, use `-v --tags test` parameters after the template name.
57
82
58
-
The `-v` flag triggers a debugging printout, and the bogus `test` flag skips the configuration deployment.
83
+
The `-v` flag enables debugging output, and the bogus `test` flag skips configuration deployment.
0 commit comments