NetOps-Enhanced this enhanced version of NetOps project. This project provides an automated network validation CI/CD pipeline powered by Batfish, Ansible, and GitHub Actions. It supports customizable configuration tests, ensuring that all network configs are validated, verified, and safely backed up. The project also supports generating device configurations using Jinja2 templates.
- Create repository secrets named TG_CHAT_ID, TG_BOT_TOKEN - for notifications in Telegram. And GH_PAT for backups into repository. Guide how create tokens are below.
- Create config for tests. In folder ./tests/config/ create config.yaml via config_guide.md.
- Create config for Nornir. In folder ./inventory configure nornir at least hosts.yaml.
- Configure your configs for validation.
- For manual configs -> paste configs into folder ./snapshots/ci_net/configs/manual/
- For auto version with jinja2 -> paste configs into folder ./snapshots/ci_net/device-yaml/ config guide
You can customize -> jinja2 templates, tests, configs and etc. for nornir. Project map below.
For security in the CI workflow, use Ruff lint to validate all Python scripts, including tests. The test suite also includes validation tests and security tests, which rely on the test configuration.
⚠️ Note: This project includes a basic default test, but for the best results you should create and customize your own validation tests.
⚠️ Note: This project includes a basic Nornir config only for connection test, for the best results you should create and customize your own Nornir configs.
On config push, the CI/CD pipeline steps:
- Sets up Python 3.11
- Install requirements
- Quick lint all python scripts with ruff
- Downloads and starts Batfish in Docker
- Prepares Batfish directories
- Generates configs from YAML (if present)
- Ensure Batfish snapshot folder exists (Ansible)
- Runs PyTest validation
- Notify in Telegram Success or Failure
- Creates backup of generated configs (on success)
- Commits and pushes backups to the repo (on success)
- Deploy configs (Nornir)
- Notify in telegram that Deploy Successfuly or not
Out of the box, the project supports generating configs from YAML for Cisco, Juniper, and Palo Alto Networks. In fact, the project supports all vendors supported by batfish but configuration generation is manual except for the three vendors mentioned above. But you can create your own jinja2 template for config generation.
This project includes many directories, structured as illustrated below:
NetOps-Enhanced/
├── .github/
│ └── workflows/
│ ├── CI_Validation.yml
│ └── CD_Deploy.yml
│
├── backup/ <-- Backup storage for validated configs
│ └── *.cfg
│
├── inventory <-- Inventory for nornir
│ ├── defaults.yaml
│ ├── groups.yaml
│ └── hosts.yaml
│
├── requirements
│ ├── ci_requirements.txt
│ └── cd_requirements.txt
│
├── ansible/
│ ├── hosts
│ └── playbook.yml
│
├── snapshots/
│ └── ci_net/
│ ├── configs/
│ │ ├── manual/
│ │ │ └── *.cfg
│ │ └──generated/
│ │ └── *.cfg
│ └── device-yaml/
│ ├── Device_yaml_guide.md
│ └── *.yaml
│
├── tests/
│ ├── security/
│ │ └── test_security.py
│ ├── validation/
│ │ └── test_validation.py
│ └── config/
│ └── config_guide.md
│
├── tools/
│ ├── templates/
│ │ └── *.j2
│ ├── conf-generator.py
│ ├── deploy_connect.py
│ └── render_config.py
│
├── config.yaml <-- Config for nornir
├── README.md
└── LICENSE
-
GitHub Personal Access Token (GH_PAT)
- Go to GitHub -> Settings -> Developer settings -> Personal access tokens -> Tokens (classic) -> Generate new token.
- Select scopes: repo (for repository access) and workflow (for GitHub Actions).
- Copy the token.
- Go to your repository -> Settings -> Secrets -> Actions -> New repository secret.
- Name it GH_PAT and paste the token.
-
Telegram Bot Token (TG_BOT_TOKEN)
- Open Telegram and search for BotFather.
- Create new bot.
- Copy the API token given by BotFather.
- Go to your repository -> Settings -> Secrets -> New repository secret.
- Name it TG_BOT_TOKEN and paste the token.
-
Telegram Chat ID (TG_CHAT_ID)
- Open Telegram and search for @userinfobot.
- Start the bot and send /start.
- The bot will reply with your chat ID.
- Go to repository secrets -> New secret -> Name it TG_CHAT_ID and paste the ID.