# rhastie/ansible-ztp-example architecture

> Architecture diagram of the GitHub repository rhastie/ansible-ztp-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rhastie/ansible-ztp-example
- Repository: https://github.com/rhastie/ansible-ztp-example

## Overview

##### Project type and purpose
- This is an infrastructure-automation project implemented in Ansible.
- It orchestrates the setup and management of a Zero-Touch Provisioning (ZTP) server (running ISC-DHCP and vsftpd) and generates/deploys Mellanox Onyx switch configurations.

##### File structure
- Top-level ansible.cfg, an inventory file (hosts), and group_vars define the controller configuration and target host variables.
- A conf directory holds sample ZTP/static configuration snippets.
- A set of YAML playbooks (e.g., playbook-ztp-setup.yml, playbook-ztp-conf-generate.yml) invoke collections of roles.
- The roles directory contains discrete, reusable Ansible roles:
- ztp-install-packages: installs ISC-DHCP & vsftpd on the server
- ztp-init: bootstraps a local repo for config files
- ztp-create-config: Jinja2 templates → DHCP/host configs
- ztp-push-dhcp & ztp-push-data: push generated configs to remote ZTP servers
- mlnx-oynx-conf-generator: generate default Onyx device configs
- set-link-speed-example: post-ZTP per-switch tasks

##### README insights
- The ZTP server uses DHCP for IP assignment and FTP for serving switch images/configs.
- The playbooks can be chained (playbook-ztp-complete) or run individually.
- Variables live in group_vars and hosts, templates in roles/**/templates and conf/ztp.

##### Main components
a. Ansible Controller (your laptop/CI)
- ansible.cfg, inventory (hosts), group_vars, conf, playbooks, roles, templates
b. Remote ZTP Server(s)
- Running on Debian-like OS
- ISC-DHCP-Server service
- vsftpd service
- Local directory of generated configs
c. Mellanox Onyx Switches
- On ZTP boot, they DHCP-discover and FTP-pull their configs
d. External services & repositories
- Package repository (apt) for installing ISC-DHCP, vsftpd
- Git repo for Ansible code (implicit)

##### Relationships and interactions
- Controller reads inventory & vars → executes playbooks → loads roles →
- ztp-install-packages: SSH → apt install services on ZTP server
- ztp-init: SSH → prepare local config workspace
- ztp-create-config: local Jinja2 templating → generate dhcpd.conf & host files
- playbook-mlnx-oynx-conf-generate: local templating → switch config files
- ztp-push-dhcp & ztp-push-data: SSH/SCP → push files to ZTP server directories
- ZTP server’s DHCP and FTP services then interact with switches at boot time

##### Architectural patterns and principles
- Modular roles (single responsibility)
- Separation of concerns:
- Inventory & group_vars manage environment data
- Templates (views) generate content
- Roles (controllers) enact changes
- conf folder holds sample static files
- Idempotent design: repeated runs don’t drift state
- Extensibility: add new roles for additional device families

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Ansible Controller Components
    subgraph "Ansible Controller"
        direction TB
        cfg["ansible.cfg"]:::control
        hosts["hosts (Inventory)"]:::control
        gv_vars[(group_vars)]:::datastore
        conf_dir[(conf directory)]:::datastore
        subgraph "Playbooks"
            direction TB
            pb_setup["playbook-ztp-setup.yml"]:::control
            pb_init["playbook-ztp-init.yml"]:::control
            pb_confgen["playbook-ztp-conf-generate.yml"]:::control
            pb_pushdata["playbook-ztp-push-data.yml"]:::control
            pb_mlnx["playbook-mlnx-oynx-conf-generate.yml"]:::control
            pb_speed["playbook-set-int-speed.yml"]:::control
            pb_complete["playbook-ztp-complete.yml"]:::control
        end
        subgraph "Roles"
            direction TB
            subgraph "ztp-install-packages"
                direction TB
                ztp_install_dir["role directory"]:::control
                ztp_install_tasks["tasks/main.yaml"]:::control
                ztp_install_template["templates/dhcp.mlnx-oynx.default"]:::datastore
            end
            subgraph "ztp-init"
                direction TB
                ztp_init_dir["role directory"]:::control
                ztp_init_tasks["tasks/main.yaml"]:::control
                ztp_init_vars["vars/main.yaml"]:::datastore
            end
            subgraph "ztp-create-config"
                direction TB
                ztp_create_dir["role directory"]:::control
                ztp_create_tasks["tasks/main.yaml"]:::control
                ztp_create_t1["templates/dhcp.j2"]:::datastore
                ztp_create_t2["templates/host.j2"]:::datastore
            end
            subgraph "ztp-push-dhcp"
                direction TB
                ztp_push_dir["role directory"]:::control
                ztp_push_tasks["tasks/main.yaml"]:::control
                ztp_push_vars["vars/main.yaml"]:::datastore
            end
            subgraph "mlnx-oynx-conf-generator"
                direction TB
                mlnx_conf_dir["role directory"]:::control
                mlnx_conf_tasks["tasks/main.yaml"]:::control
                mlnx_conf_template["templates/common.conf.mlnx-oynx.default"]:::datastore
                mlnx_conf_gv["group_vars/mlnx-oynx-conf-generator.yaml"]:::datastore
            end
            subgraph "set-link-speed-example"
                direction TB
                link_speed_dir["role directory"]:::control
                link_speed_tasks["tasks/main.yml"]:::control
            end
        end
    end

    %% ZTP Server
    subgraph "ZTP Server"
        direction TB
        dhcp["ISC-DHCP-Server"]:::service
        ftp["vsftpd"]:::service
        server_conf[(generated configs)]:::datastore
    end

    %% Network and Switches
    net((Management Network)):::network
    switches["Mellanox Onyx Switches"]:::service

    %% Data Flows
    cfg -->|reads| hosts
    hosts --> gv_vars
    gv_vars --> pb_confgen
    conf_dir --> pb_confgen
    pb_confgen -->|generates| server_conf
    pb_mlnx -->|generates| server_conf
    pb_setup -->|SSH/apt install| dhcp
    pb_setup -->|SSH/apt install| ftp
    pb_init -->|SSH/prepare workspace| server_conf
    pb_pushdata -->|SSH/SCP| server_conf
    server_conf -->|served via FTP| switches
    dhcp -->|DHCP discover| switches
    switches -->|boot| net

    %% Connections Controller to ZTP Server
    pb_setup -->|SSH| dhcp
    pb_setup -->|SSH| ftp
    pb_pushdata -->|SCP| server_conf

    %% Click Events
    click cfg "https://github.com/rhastie/ansible-ztp-example/blob/master/./ansible.cfg"
    click hosts "https://github.com/rhastie/ansible-ztp-example/tree/master/./hosts"
    click gv_vars "https://github.com/rhastie/ansible-ztp-example/blob/master/./group_vars/all/vars.yaml"
    click conf_dir "https://github.com/rhastie/ansible-ztp-example/tree/master/./conf"
    click pb_setup "https://github.com/rhastie/ansible-ztp-example/blob/master/./playbook-ztp-setup.yml"
    click pb_init "https://github.com/rhastie/ansible-ztp-example/blob/master/./playbook-ztp-init.yml"
    click pb_confgen "https://github.com/rhastie/ansible-ztp-example/blob/master/./playbook-ztp-conf-generate.yml"
    click pb_pushdata "https://github.com/rhastie/ansible-ztp-example/blob/master/./playbook-ztp-push-data.yml"
    click pb_mlnx "https://github.com/rhastie/ansible-ztp-example/blob/master/./playbook-mlnx-oynx-conf-generate.yml"
    click pb_speed "https://github.com/rhastie/ansible-ztp-example/blob/master/./playbook-set-int-speed.yml"
    click pb_complete "https://github.com/rhastie/ansible-ztp-example/blob/master/./playbook-ztp-complete.yml"
    click ztp_install_dir "https://github.com/rhastie/ansible-ztp-example/tree/master/./roles/ztp-install-packages"
    click ztp_install_tasks "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-install-packages/tasks/main.yaml"
    click ztp_install_template "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-install-packages/templates/dhcp.mlnx-oynx.default"
    click ztp_init_dir "https://github.com/rhastie/ansible-ztp-example/tree/master/./roles/ztp-init"
    click ztp_init_tasks "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-init/tasks/main.yaml"
    click ztp_init_vars "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-init/vars/main.yaml"
    click ztp_create_dir "https://github.com/rhastie/ansible-ztp-example/tree/master/./roles/ztp-create-config"
    click ztp_create_tasks "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-create-config/tasks/main.yaml"
    click ztp_create_t1 "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-create-config/templates/dhcp.j2"
    click ztp_create_t2 "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-create-config/templates/host.j2"
    click ztp_push_dir "https://github.com/rhastie/ansible-ztp-example/tree/master/./roles/ztp-push-dhcp"
    click ztp_push_tasks "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-push-dhcp/tasks/main.yaml"
    click ztp_push_vars "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/ztp-push-dhcp/vars/main.yaml"
    click mlnx_conf_dir "https://github.com/rhastie/ansible-ztp-example/tree/master/./roles/mlnx-oynx-conf-generator"
    click mlnx_conf_tasks "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/mlnx-oynx-conf-generator/tasks/main.yaml"
    click mlnx_conf_template "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/mlnx-oynx-conf-generator/templates/common.conf.mlnx-oynx.default"
    click mlnx_conf_gv "https://github.com/rhastie/ansible-ztp-example/blob/master/./group_vars/mlnx-oynx/mlnx-oynx-conf-generator.yaml"
    click link_speed_dir "https://github.com/rhastie/ansible-ztp-example/tree/master/./roles/set-link-speed-example"
    click link_speed_tasks "https://github.com/rhastie/ansible-ztp-example/blob/master/./roles/set-link-speed-example/tasks/main.yml"

    %% Styles
    classDef control fill:#ADD8E6,stroke:#000
    classDef datastore fill:#90EE90,stroke:#000
    classDef service fill:#FFA500,stroke:#000
    classDef network fill:#D3D3D3,stroke:#000,stroke-dasharray: 5 5
```
