# ayoubchkur/ansible-bgp-validation-lab architecture

> Architecture diagram of the GitHub repository ayoubchkur/ansible-bgp-validation-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ayoubchkur/ansible-bgp-validation-lab
- Repository: https://github.com/ayoubchkur/ansible-bgp-validation-lab

## Overview

##### Project type and purpose
- This is a network-automation and validation tool that builds, configures and tests a multi-AS BGP/OSPF topology in PNETLab using Cisco IOL images.
- It combines Infrastructure as Code (Ansible, Jinja2), network device APIs (NAPALM/Netmiko), a network simulator (PNETLab/Cisco IOL), a validation engine (Batfish/pybatfish) and CI/CD (GitHub Actions).

##### File structure
- Top-level files only:
- .gitignore – standard VCS ignore rules
- README.md – full description of tools and workflow
- No subdirectories in the tree, but README mentions components that live conceptually in the repo (Ansible playbooks & roles, Jinja2 templates, Batfish tests, CI workflow).

##### README for additional insights
- Tools Used: PNETLab, Cisco IOL, Ansible, Jinja2, NAPALM/Netmiko, Batfish, GitHub Actions
- Features section outlines the workflow: render configs → push to devices or export for simulator → load into Batfish → run validation → CI/CD pipeline triggers on code change.

##### Main components
a. Version Control & CI Layer
- GitHub repo (Ansible playbooks, Jinja2 templates, Batfish test definitions)
- GitHub Actions runner (CI pipeline that kicks off validation jobs on push)
b. Config Generation & Deployment Layer
- Ansible controller with Jinja2 engine
- Optional NAPALM / Netmiko connectors for direct device push
- Generated startup-config artifacts for PNETLab import
c. Simulation & Test Environment
- PNETLab instance hosting Cisco IOL routers (multi-AS BGP/OSPF topology)
- Batfish container (with pybatfish) that ingests device configs and sim state
d. Validation & Reporting
- Batfish-driven checks: BGP session health, route leakage tests
- CI status reports back to GitHub
e. Developer Workstation (optional)
- Local testing of playbooks or manual invocation of Batfish before push

##### Relationships and interactions
- Developer pushes code → GitHub repo
- GitHub Actions clone repo → run Ansible playbooks + Jinja2 → generate configs
- Ansible either:
- Uses NAPALM/Netmiko to push directly into real/simulated devices OR
- Exports config files that PNETLab imports into IOL routers
- After config load, GitHub Actions spins up Batfish container → loads the same configs → runs pybatfish tests
- Test results (pass/fail, routing table snapshots) flow back to GitHub Actions → developer sees CI status

##### Architectural patterns and principles
- Separation of concerns:
- IaC (Ansible + Jinja2) vs. validation (Batfish) vs. orchestration (CI) vs. simulation (PNETLab)
- Declarative config pipelines, idempotent playbooks
- Continuous validation ensures network invariants are met on every change
- Modular test definitions in Batfish, reusable Jinja2 network templates

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Developer Workstation"
        DevWL["Developer Workstation"]:::dev
    end

    subgraph "Version Control & CI Layer"
        GHRepo["GitHub Repo"]:::ci
        README["README.md"]:::ci
        GitIgnore[".gitignore"]:::ci
    end

    subgraph "Config Generation & Deployment Layer"
        Ansible["Ansible Controller + Jinja2"]:::orchestr
        NAPALM["NAPALM/Netmiko"]:::orchestr
        Artifacts["Config Artifacts"]:::orchestr
    end

    subgraph "Simulation Environment"
        PNETLab["PNETLab (Cisco IOL)"]:::sim
    end

    subgraph "Validation & Reporting"
        Batfish["Batfish Container"]:::val
        CIReport["CI Status Report"]:::ci
    end

    DevWL -->|"push code"| GHRepo
    GHRepo --> GHActions["GitHub Actions"]:::ci
    GHActions -->|"render templates"| Ansible
    Ansible -->|"optional push"| NAPALM
    Ansible -->|"export configs"| Artifacts
    Artifacts -->|"import configs"| PNETLab
    GHActions -->|"spin up"| Batfish
    Batfish -->|"ingest configs"| Batfish
    Batfish -->|"run tests"| Batfish
    Batfish -->|"send results"| CIReport
    CIReport -->|"update status"| GHRepo

    click README "https://github.com/ayoubchkur/ansible-bgp-validation-lab/blob/main/README.md"
    click GitIgnore "https://github.com/ayoubchkur/ansible-bgp-validation-lab/blob/main/.gitignore"

    classDef ci fill:#D0E8FF,stroke:#004080,color:#000
    classDef orchestr fill:#DFFFD0,stroke:#408000,color:#000
    classDef sim fill:#F0F0F0,stroke:#666666,color:#000
    classDef val fill:#FFE0B2,stroke:#804000,color:#000
    classDef dev fill:#E8D0FF,stroke:#800080,color:#000
```
