How rhastie/ansible-ztp-example works
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