Skip to content

Inventory

To accommodate for smooth transition from lab deployment to subsequent automation activities, containerlab generates inventory files for different automation tools.

Ansible#

Ansible inventory is generated automatically for every lab. The inventory file can be found in the lab directory under the ansible-inventory.yml name.

Lab nodes are grouped under their kinds in the inventory so that the users can selectively choose the right group of nodes in the playbooks.

name: ansible
topology:
  nodes:
    r1:
      kind: crpd
      image: crpd:latest

    r2:
      kind: ceos
      image: ceos:latest

    r3:
      kind: ceos
      image: ceos:latest

    grafana:
      kind: linux
      image: grafana/grafana:7.4.3
all:
  children:
    crpd:
      hosts:
        clab-ansible-r1:
          ansible_host: <mgmt-ipv4-address>
    ceos:
      hosts:
        clab-ansible-r2:
          ansible_host: <mgmt-ipv4-address>
        clab-ansible-r3:
          ansible_host: <mgmt-ipv4-address>
    linux:
      hosts:
        clab-ansible-grafana:
          ansible_host: <mgmt-ipv4-address>

User-defined groups#

Users can enforce custom grouping of nodes in the inventory by adding the ansible-inventory label to the node definition:

name: custom-groups
topology:
  nodes:
    node1:
      # <some node config data>
      labels:
        ansible-group: spine
    node2:
      # <some node config data>
      labels:
        ansible-group: extra_group

As a result of this configuration, the generated inventory will look like this:

  children:
    srl:
      hosts:
        clab-custom-groups-node1:
          ansible_host: 172.100.100.11
        clab-custom-groups-node2:
          ansible_host: 172.100.100.12
    extra_group:
      hosts:
        clab-custom-groups-node2:
          ansible_host: 172.100.100.12
    spine:
      hosts:
        clab-custom-groups-node1:
          ansible_host: 172.100.100.11


Back to top