UFW Parser
Collect UFW firewall rules from your servers and export them as tables, CSV, Excel or Ansible YAML
Overview
UFW Parser fetches and parses UFW firewall rules from Linux servers — locally or remotely over SSH — and presents them in a clean, tabular, exportable format.
It is built for reviewing and documenting firewall configuration across a fleet: rules are grouped per server and can be exported straight to Ansible host_vars YAML to bring existing servers under configuration management.
Rules are read from the same lines UFW rebuilds its own rule list from, so allow, deny, reject and limit rules, IPv6 addresses, port ranges and routed rules all come through as UFW stores them.
Key Features
- Local or remote — Read UFW rules from local copies or over SSH with sudo, including SSH agent support. Host keys are checked against known_hosts.
- Every rule type — Allow, deny, reject and limit rules, logging, incoming, outgoing and routed rules, port lists and ranges, IPv4 and IPv6 addresses with prefix length.
- Per-server grouping — Groups and consolidates firewall rules per server; servers are read in parallel.
- Multiple export formats — Terminal table, CSV, Excel, or Ansible host_vars YAML with community.general.ufw parameters.
- Ready for scripts — Exit codes report servers that could not be read and skipped rules; failures are listed at the end of the run.
- Structured logs — Logging with file rotation, plus a debug mode.
- Modular design — CLI-driven and easy to extend.
Installation
Requirements
- Python 3.10 or newer
- For remote servers: SSH access with the host key in known_hosts, and sudo without a password for reading the rule files
git clone https://github.com/qf3l3k/ufw_parser.git
cd ufw_parser
pip install .Configuration
Copy examples/hosts.example.yml to ~/.config/ufw_parser/hosts.yml and list the servers and how to reach them:
servers:
web-01:
hostname: web-01.example.com
processing: local
rule_path: /path/to/backup/web-01.example.com/etc/ufw
db-01:
hostname: db-01.example.com
processing: remote
ssh_user: admin
use_ssh_agent: true
rule_path: /etc/ufwUsage
ufw_parser -c ~/.config/ufw_parser/hosts.yml -o ansible_yaml -of ~/exports/| Option | Description |
|---|---|
-c, --config | Path to the hosts configuration file (default ~/.config/ufw_parser/hosts.yml) |
-o, --output | Output format: screen (default), csv, excel or ansible_yaml |
-of, --output_folder | Destination folder for exports (default ~/.config/ufw_parser/) |
-l, --log | Log files directory (default ~/.config/ufw_parser/) |
-j, --jobs | Number of servers read in parallel (default 8) |
--ssh-timeout | Seconds for SSH connect, login and each remote command (default 15) |
-d, --debug | Enable debug logging |
-v, --version | Show the version |
Related Resources
- Full documentation — Requirements, installation and usage on docs.chaintools.tech
- UFW documentation — Uncomplicated Firewall on Ubuntu
- Ansible host_vars — Where the exported YAML fits in an Ansible inventory
- Report an issue — Bugs and feature requests
Need something custom?
We build tooling and automation for node operators and chain teams, and can help you deploy or adapt this tool to your setup.
