Testing intent-based RouterOS automation with the official CHR image in Containerlab

We built a fully centralized, intent-based automation system for MikroTik networks with Ansible. The intended state of each network is defined in one place, and Ansible applies it to every router. Before a change reaches a router, it runs against a copy of the network in Containerlab.

Containerlab 0.82.0 made these labs simpler to build. Its new mikrotik_chr kind runs MikroTik's official mikrotik/chr image from Docker Hub as published, on amd64 and arm64. There is no vrnetlab build anymore, and Containerlab pulls the image on the first deploy. In the test runs in the pull request, a router was ready after about a minute, with or without KVM. Each router gets about 256 MiB of memory by default, so we can build fairly large MikroTik networks to test against.

https://containerlab.dev/manual/kinds/mikrotik_chr/

Thanks to MikroTik for publishing amd64 and arm64 images.

A small lab

Save this as mikrotik.clab.yml:

name: mikrotik
topology:
  kinds:
    mikrotik_chr:
      image: mikrotik/chr:7.24.5
  nodes:
    r1:
      kind: mikrotik_chr
    r2:
      kind: mikrotik_chr
    r3:
      kind: mikrotik_chr
  links:
    - endpoints: ["r1:ether2", "r2:ether2"]
    - endpoints: ["r2:ether3", "r3:ether2"]
    - endpoints: ["r3:ether3", "r1:ether3"]

Start the lab, log in to r1 and remove the lab again:

sudo containerlab deploy -t mikrotik.clab.yml
ssh admin@clab-mikrotik-r1
sudo containerlab destroy -t mikrotik.clab.yml

The default login is admin with the password admin. ether1 is the management port in its own VRF, so data links start at ether2. SSH, the API and REST answer on the management address, so Ansible reaches the lab routers the same way it reaches real ones. Labs on the older mikrotik_ros kind move over by changing kind and image.

How we use it

Our initial work is open source as ansible-mikrotik. It lags a bit behind what we use today. Our Containerlab guide shows how we build and use these labs. We use the same approach for OT WANs, campus networks and data center fabrics such as the one at sciCORE, University of Basel.

https://narrowin.com/mikrotik