Skip to content

Commit 08689b7

Browse files
authored
Update intent based ansible tutorial (#201)
1 parent 91ea1b3 commit 08689b7

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

docs/tutorials/programmability/ansible/intent-based-management/config.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If you have installed the [fcli](https://github.com/srl-labs/nornir-srl) tool, y
1212

1313
=== "LLDP neighbors"
1414
```bash
15-
❯ fcli lldp
15+
❯ fcli -t topo.clab.yml lldp
1616
LLDP Neighbors
1717
+----------------------------------------------------------------------------+
1818
| Node | interface | Nbr-System | Nbr-port | Nbr-port-desc |
@@ -42,7 +42,7 @@ If you have installed the [fcli](https://github.com/srl-labs/nornir-srl) tool, y
4242
```
4343
=== "Network instances and interfaces"
4444
```bash
45-
❯ fcli ni
45+
❯ fcli -t topo.clab.yml ni
4646
Network Instances and interfaces
4747
+---------------------------------------------------------------------------------------------------------------------+
4848
| Node | NI | oper | type | router-id | Subitf | assoc-ni | if-oper | ipv4 | mtu | vlan |
@@ -161,14 +161,14 @@ Copy the files in `intent_examples/infra/underlay_with_fabric_intent` into the `
161161

162162
```bash
163163
cp intent_examples/infra/underlay_with_fabric_intent/* intent
164-
ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
164+
uv run ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
165165
```
166166

167167
This will deploy the underlay configuration to all the nodes of the fabric. Let's check the fabric status with `fcli`:
168168

169169
=== "BGP Peers"
170170
```bash
171-
❯ fcli bgp-peers
171+
❯ fcli -t topo.clab.yml bgp-peers
172172
BGP Peers
173173
Inventory filter:{'fabric': 'yes'}
174174
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
@@ -216,7 +216,7 @@ This will deploy the underlay configuration to all the nodes of the fabric. Let'
216216
```
217217
=== "Network instances and interfaces"
218218
```bash
219-
❯ fcli ni
219+
❯ fcli -t topo.clab.yml ni
220220
Network Instances and interfaces
221221
Inventory filter:{'fabric': 'yes'}
222222
+-----------------------------------------------------------------------------------------------------------------------------------------+
@@ -268,7 +268,7 @@ Alternatively, we could opt to use _BGP unnumbered_ inter-switch links (dynamic
268268

269269
=== "BGP peers with BGP unnumbered peers"
270270
```bash
271-
❯ fcli bgp-peers
271+
❯ fcli -t topo.clab.yml bgp-peers
272272
BGP Peers
273273
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
274274
| | | | AF: EVPN | AF: IPv4 | AF: IPv6 | | | | | | |
@@ -321,7 +321,7 @@ Alternative to a Fabric Intent, we can use level-1 Infra Intents. This gives mor
321321

322322
```bash
323323
rm -f intent/* && cp intent_examples/infra/underlay_with_level1_intents/* ./intent
324-
ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
324+
uv run ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
325325
```
326326

327327
The schema files for these level-1 intents exist in the `playbooks/roles/infra/criteria` directory. There is a JSON-schema file per top-level level-1 resource.
@@ -391,7 +391,7 @@ Copy over above 2 files from `intent_examples/services` into `intent/` and run t
391391

392392
```
393393
cp intent_examples/services/mh_access-1.yml intent_examples/services/host_infra_itf_tags.yml intent
394-
ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
394+
uv run ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
395395
```
396396

397397
!!!note
@@ -401,7 +401,7 @@ Check the relevant state of the fabric:
401401

402402
=== "LAGs"
403403
```bash
404-
❯ fcli lag
404+
❯ fcli -t topo.clab.yml lag
405405
LAGs
406406
Inventory filter:{'fabric': 'yes'}
407407
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@@ -414,7 +414,7 @@ Check the relevant state of the fabric:
414414
```
415415
=== "Ethernet Segments"
416416
```bash
417-
❯ fcli es
417+
❯ fcli -t topo.clab.yml es
418418
Ethernet Segments
419419
Inventory filter:{'fabric': 'yes'}
420420
+--------------------------------------------------------------------------------------------+
@@ -452,14 +452,14 @@ Let's copy this file from the intent examples directory and deploy it:
452452

453453
```
454454
cp intent_examples/services/l2vpn_101.yml intent
455-
ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
455+
uv run ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
456456
```
457457

458458
Check the state of the service and the Ethernet Segments in the fabric with `fcli`:
459459

460460
=== "Network Instances"
461461
```bash
462-
❯ fcli ni -f ni=subnet-1
462+
❯ fcli -t topo.clab.yml ni -f ni=subnet-1
463463
Network Instances and interfaces
464464
Fields filter:{'ni': 'subnet-1'}
465465
+-----------------------------------------------------------------------------------------------------------+
@@ -472,7 +472,7 @@ Check the state of the service and the Ethernet Segments in the fabric with `fcl
472472
```
473473
=== "Ethernet Segments"
474474
```bash
475-
❯ fcli es
475+
❯ fcli -t topo.clab.yml es
476476
Ethernet Segments
477477
+------------------------------------------------------------------------------------------------------------------------------+
478478
| Node | name | esi | mh-mode | oper | itf | ni-peers |
@@ -496,14 +496,14 @@ The `mh_access_2.yml` file contains the 2 extra `mh_access` intents, the `l2vpn_
496496
```
497497
cp intent_examples/services/mh_access-2.yml intent
498498
cp intent_examples/services/l2vpn_101bis.yml intent/l2vpn_101.yml # replaces the previous
499-
ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
499+
uv run ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
500500
```
501501
502502
Verify the LAGs, ES's and mac-vrf `subnet-1`:
503503
504504
=== "LAGs"
505505
```bash
506-
❯ fcli lag
506+
❯ fcli -t topo.clab.yml lag
507507
LAGs
508508
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
509509
| Node | lag | oper | mtu | min | desc | type | speed | stby-sig | lacp-key | lacp-itvl | lacp-mode | lacp-sysid | lacp-prio | act | member-itf | member-oper |
@@ -521,7 +521,7 @@ Verify the LAGs, ES's and mac-vrf `subnet-1`:
521521
```
522522
=== "Ethernet Segments"
523523
```bash
524-
❯ fcli es
524+
❯ fcli -t topo.clab.yml es
525525
Ethernet Segments
526526
+------------------------------------------------------------------------------------------------------------------------------+
527527
| Node | name | esi | mh-mode | oper | itf | ni-peers |
@@ -539,7 +539,7 @@ Verify the LAGs, ES's and mac-vrf `subnet-1`:
539539
```
540540
=== "mac-vrf `subnet-1`"
541541
```bash
542-
❯ fcli ni -f ni=subnet-1
542+
❯ fcli -t topo.clab.yml ni -f ni=subnet-1
543543
Network Instances and interfaces
544544
Fields filter:{'ni': 'subnet-1'}
545545
+-----------------------------------------------------------------------------------------------------------+
@@ -587,7 +587,7 @@ Verify the mac-table of `subnet-1`:
587587
588588
=== "mac-vrf `subnet-1`"
589589
```bash
590-
❯ fcli mac -f ni=subnet-1
590+
❯ fcli -t topo.clab.yml mac -f ni=subnet-1
591591
MAC Table
592592
Fields filter:{'ni': 'subnet-1'}
593593
+--------------------------------------------------------------------------------------------------------------------------+
@@ -699,12 +699,12 @@ Now the L3VPN service is defined using the two L2VPN intents (subnets) together
699699
cp intent_examples/services/mh_access-3.yml intent
700700
cp intent_examples/services/l2vpn_102.yml intent
701701
cp intent_examples/services/l3vpn_2001.yml intent
702-
ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
702+
uv ansible-playbook -i inv -e intent_dir=${PWD}/intent --diff playbooks/cf_fabric.yml
703703
```
704704

705705
=== "ip-vrf `ipvrf-1`"
706706
```bash
707-
❯ fcli ni -f ni=ipvrf-1
707+
❯ fcli -t topo.clab.yml ni -f ni=ipvrf-1
708708
Network Instances and interfaces
709709
Fields filter:{'ni': 'ipvrf-1'}
710710
+----------------------------------------------------------------------------------------------------------------------+
@@ -746,7 +746,7 @@ You can now verify inter-subnet routing between clients in different subnets.
746746
```
747747
=== "ARP table"
748748
```bash
749-
❯ fcli arp -f ni="*ipvrf-1*"
749+
❯ fcli -t topo.clab.yml arp -f ni="*ipvrf-1*"
750750
ARP table
751751
Fields filter:{'ni': '*ipvrf-1*'}
752752
+-------------------------------------------------------------------------------------------------------+
@@ -814,7 +814,7 @@ The `cf_fabric` playbook leverages the _commit confirm_ functionality of SR Linu
814814
To use this functionality, specify the extra variable `confirm_timeout` when you run the playbook, e.g.:
815815

816816
```bash
817-
ansible-playbook -i inv -e intent_dir=${PWD}/intent -e confirm_timeout=60 --diff playbooks/cf_fabric.yml
817+
uv run ansible-playbook -i inv -e intent_dir=${PWD}/intent -e confirm_timeout=60 --diff playbooks/cf_fabric.yml
818818
```
819819

820820
This will make the playbook run interactive and it will ask for explicit confirmation to leave the latest commit intact. If no confirmation is given, the commits are rolled back after the specified timeout.

docs/tutorials/programmability/ansible/intent-based-management/env.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ The following sections assume you are in the `intent-based-ansible-lab` director
1515

1616
## Install Ansible and dependencies
1717

18-
- To run the playbooks in the above repo, Ansible and related dependencies must be installed. The recommended way is to create a Python virtual environment and install the packages in that environment. Next to the Python packages, the `nokia.srlinux` Ansible collection is required that provides the connection plugin to interact with SR Linux using JSON-RPC.
18+
- To run the playbooks in the above repo, Ansible and related dependencies must be installed. The recommended way is to use uv. Next to the Python packages, the `nokia.srlinux` Ansible collection is required that provides the connection plugin to interact with SR Linux using JSON-RPC.
1919

20-
```bash title="Creating a venv and installing dependencies"
21-
python3 -mvenv .venv
22-
source .venv/bin/activate
23-
pip install -U pip && pip install -r requirements.txt
24-
ansible-galaxy collection install nokia.srlinux
20+
21+
```bash title="Installing dependencies"
22+
# Install uv (Linux/macOS)
23+
curl -LsSf https://astral.sh/uv/install.sh | sh
24+
25+
# Sync uv
26+
uv sync
27+
28+
# Install the Nokia SR Linux Ansible collection
29+
uv run ansible-galaxy collection install nokia.srlinux
2530
```
2631

2732
- Ensure you have the [Containerlab](https://containerlab.dev/install)[^2] installed and are meeting its installation requirements.
@@ -30,15 +35,15 @@ The following sections assume you are in the `intent-based-ansible-lab` director
3035
`fcli` is not required to run the project, but it's useful to verify the state of the fabric after running the playbook and is used throughout this tutorial to illustrate the effects of the Ansible playbooks. It is packaged in a container and run via a shell alias via the following command:
3136
3237
```bash
33-
source .aliases.rc
38+
uv tool install git+https://github.com/srl-labs/nornir-srl
3439
```
3540
3641
## Deploying the lab
3742
3843
You need an SR Linux test topology to run the Ansible playbook and roles against. We will use [Containerlab](https://containerlab.dev/) to create a lab environment with 6 SR Linux nodes: 4 leaves and 2 spines:
3944
4045
```bash
41-
sudo containerlab deploy -t topo.yml --reconfigure
46+
containerlab deploy -t topo.clab.yml --reconfigure
4247
```
4348
4449
This will create a lab environment with 6 SR Linux nodes and a set of Linux containers to act as hosts:
@@ -51,7 +56,7 @@ This will create a lab environment with 6 SR Linux nodes and a set of Linux cont
5156
Containerlab populates the `/etc/hosts` file on the host machine with the IP addresses of the deployed nodes. This allows Ansible to connect to the nodes that has a matching inventory file inside the `inv` directory.
5257
5358
```bash title="Verifying that all lab nodes are up and running"
54-
sudo containerlab inspect -t topo.yml
59+
containerlab inspect -t topo.clab.yml
5560
```
5661
5762
With the lab deployed, we can now explore the project's structure and understand the role's layout that powers the intent-based configuration management.

docs/tutorials/programmability/ansible/intent-based-management/summary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The reasons for this approach are:
1717
This is a 'low-code' approach to network automation using only Jinja templating and the Ansible domain-specific language. It does require some basic development and troubleshooting skills as playbook errors will happen and debugging will be required. For example, when adding new capabilities to roles/templates, invalid data in intent variables, when SR Linux model changes happen across software releases, etc. These events may break template rendering inside the roles. Most of the logic is embedded in the Jinja templates but runtime errors are not always easy to pinpoint as Ansible does not provide a stack trace or position of failure within the template. A general troubleshooting process is as follows:
1818

1919
1. Reduce the output by limiting the playbook run to a single host that exhibits the problem (`hosts` variable in `cf_fabric.yml`)
20-
2. run `ansible-playbook` with the `-vvv` option to get verbose output during the playbook run
20+
2. run `uv run ansible-playbook` with the `-vvv` option to get verbose output during the playbook run
2121
3. insert `debug` tasks at strategic places in the playbook to narrow down the problem. Debugging variables `my_intent`, which is local to the role, `intent`, which is built up incrementally as the playbook progresses and `replace`, `update` and `delete` in the `configure` role usually point you to the root cause of the problem. Running a playbook with the debug statements in place will show the values of these variables during a regular playbook run
2222

2323
_Network-wide transactions_ could be implemented with _Git_. You `git commit` your changes (intents/roles) to a Git repository after any change to intents or roles. If some issues occur during the playbook run, e.g. some nodes fail in the playbook resulting in a partial fabric-wide deployment or changes appear to be permanently service-affecting, you can revert back to a previous commit with e.g. `git revert` and run the playbook again from a known good state (intent/roles).

0 commit comments

Comments
 (0)