Home » Network Configuration Management: Ansible, Nornir และ NAPALM
Network Configuration Management: Ansible, Nornir และ NAPALM
Network Configuration Management: Ansible, Nornir และ NAPALM
Network Configuration Management คือการจัดการ configuration ของ network devices อย่างเป็นระบบ ใช้ automation tools แทน manual CLI Ansible เป็น agentless automation framework ที่ใช้ YAML playbooks, Nornir เป็น Python automation framework ที่ยืดหยุ่นสูง และ NAPALM เป็น Python library สำหรับ multi-vendor network automation
การ configure network devices ด้วย CLI ทีละตัว ช้า error-prone และไม่ scalable — configure 100 switches ด้วยมือใช้เวลาหลายวัน และมีโอกาสพิมพ์ผิด Automation tools ทำได้ใน minutes โดย consistent ทุกครั้ง พร้อม version control, rollback และ compliance checking
Tool Comparison
| Feature |
Ansible |
Nornir |
NAPALM |
| Language |
YAML (playbooks) + Python |
Python (native) |
Python (library) |
| Architecture |
Agentless (SSH/NETCONF) |
Python framework |
Python library |
| Learning Curve |
ต่ำ (YAML readable) |
ปานกลาง (ต้องรู้ Python) |
ปานกลาง (Python) |
| Multi-vendor |
ดี (modules per vendor) |
ดีมาก (pluggable) |
ดีมาก (unified API) |
| Performance |
ปานกลาง (fork per host) |
ดีมาก (threaded) |
ดี (per-device) |
| Flexibility |
ดี (roles, templates) |
ดีมาก (full Python) |
ดี (getters/setters) |
| Community |
ใหญ่มาก (Red Hat) |
กลาง-ใหญ่ |
กลาง |
Ansible for Network
| Feature |
รายละเอียด |
| Inventory |
YAML/INI file ที่ list devices + groups + variables |
| Playbook |
YAML file ที่ define tasks (what to do on which devices) |
| Modules |
cisco.ios.ios_config, arista.eos.eos_config, junipernetworks.junos.junos_config |
| Templates |
Jinja2 templates สำหรับ generate config จาก variables |
| Roles |
Reusable units (tasks + templates + vars + handlers) |
| Collections |
ansible.netcommon, cisco.ios, arista.eos, junipernetworks.junos |
| Connection |
network_cli (SSH), netconf, httpapi |
Ansible Network Modules
| Module |
Vendor |
Function |
| ios_config |
Cisco IOS |
Push configuration lines |
| ios_facts |
Cisco IOS |
Gather device facts (hostname, version, interfaces) |
| ios_command |
Cisco IOS |
Run show commands |
| eos_config |
Arista EOS |
Push configuration |
| junos_config |
Juniper Junos |
Push configuration (commit model) |
| nxos_config |
Cisco NX-OS |
Push configuration (Nexus) |
| cli_config |
Multi-vendor |
Generic CLI config push |
| net_ping |
Multi-vendor |
Ping from network device |
Nornir
| Feature |
รายละเอียด |
| คืออะไร |
Python automation framework — เขียน automation ด้วย pure Python |
| Inventory |
SimpleInventory (YAML), NetBox plugin, Ansible inventory plugin |
| Tasks |
Python functions ที่ run บนแต่ละ host |
| Plugins |
nornir_netmiko (SSH), nornir_napalm (NAPALM), nornir_scrapli |
| Concurrency |
Threaded execution (configurable num_workers) |
| ข้อดี |
Full Python power — loops, conditions, error handling, custom logic |
| ข้อดีกว่า Ansible |
Faster (threaded), more flexible (Python), better error handling |
NAPALM
| Feature |
รายละเอียด |
| คืออะไร |
Network Automation and Programmability Abstraction Layer with Multivendor support |
| Unified API |
Same Python methods สำหรับทุก vendor (get_facts, get_interfaces, load_merge_candidate) |
| Getters |
get_facts(), get_interfaces(), get_bgp_neighbors(), get_arp_table(), etc. |
| Config Management |
load_merge_candidate(), load_replace_candidate(), compare_config(), commit_config(), rollback() |
| Supported Vendors |
Cisco IOS/NX-OS/IOS-XR, Arista EOS, Juniper Junos, Huawei, MikroTik (community) |
| Integration |
ใช้ใน Ansible (napalm module), Nornir (nornir_napalm), Salt |
NAPALM Getters
| Getter |
Returns |
| get_facts() |
hostname, model, serial, OS version, uptime, interfaces |
| get_interfaces() |
Interface name, speed, MAC, admin/oper status |
| get_interfaces_ip() |
Interface IP addresses + prefixes |
| get_bgp_neighbors() |
BGP peer info, state, prefixes received/sent |
| get_lldp_neighbors() |
LLDP neighbor device + port |
| get_arp_table() |
ARP entries (IP, MAC, interface) |
| get_route_to() |
Routing table entries for destination |
| get_config() |
Running, startup, candidate config |
Configuration as Code Workflow
| Step |
Tool |
Action |
| 1. Source of Truth |
NetBox / Nautobot |
Store device inventory, IPs, VLANs, connections |
| 2. Templates |
Jinja2 |
Create config templates with variables |
| 3. Generate Config |
Ansible/Nornir + Jinja2 |
Render templates with data from SoT |
| 4. Validate |
NAPALM compare_config() |
Show diff before applying |
| 5. Deploy |
Ansible/Nornir |
Push config to devices |
| 6. Verify |
NAPALM getters / pytest |
Verify config applied correctly |
| 7. Version Control |
Git |
Track all changes in Git repository |
Best Practices
| Practice |
รายละเอียด |
| Git for configs |
ทุก config change ผ่าน Git (version control + review) |
| Templates (Jinja2) |
ใช้ templates ไม่ hardcode config (DRY principle) |
| Source of Truth |
NetBox/Nautobot เป็น single source of truth |
| CI/CD Pipeline |
Lint → validate → dry-run → deploy → verify |
| Idempotent |
Run playbook ซ้ำได้ผลเหมือนเดิม (no side effects) |
| Rollback plan |
NAPALM rollback() หรือ backup config ก่อน change |
| Start small |
เริ่มจาก read-only (facts, show commands) → config changes ทีหลัง |
ทิ้งท้าย: Network Automation = Consistent + Fast + Reliable
Config Management Ansible = YAML playbooks (easy to start, large community) Nornir = Python framework (faster, more flexible, threaded) NAPALM = unified multi-vendor API (getters + config management) Workflow: SoT (NetBox) → Jinja2 templates → generate → validate → deploy → verify Git + CI/CD + templates + SoT = Infrastructure as Code for networks
อ่านเพิ่มเติมเกี่ยวกับ Network Automation NETCONF YANG และ Network Infrastructure as Code ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com