Home » Network Automation: Ansible, Terraform, Python Netmiko, NAPALM และ GitOps
Network Automation: Ansible, Terraform, Python Netmiko, NAPALM และ GitOps
Network Automation: Ansible, Terraform, Python Netmiko, NAPALM และ GitOps
Network Automation เปลี่ยน network operations จาก manual CLI commands เป็น automated workflows Ansible ใช้ YAML playbooks สำหรับ configuration management, Terraform ใช้ Infrastructure as Code สำหรับ provisioning, Python Netmiko เป็น SSH library สำหรับ multi-vendor device automation, NAPALM เป็น abstraction layer สำหรับ network device management และ GitOps ใช้ Git เป็น single source of truth สำหรับ network configurations
Network engineers ใช้เวลา 80% กับ repetitive tasks: config changes, firmware upgrades, compliance checks, troubleshooting Manual operations ทำให้เกิด human errors (typos, inconsistencies), ใช้เวลานาน (config 100 switches ทีละตัว), ไม่มี audit trail ที่ดี Network automation ลด errors, เพิ่มความเร็ว, ให้ consistency และ repeatability
Automation Tools Comparison
| Tool |
Type |
Language |
Best For |
| Ansible |
Configuration Management |
YAML (playbooks) |
Config push, compliance, multi-vendor (agentless, SSH) |
| Terraform |
Infrastructure as Code |
HCL |
Cloud/network provisioning (declarative, state management) |
| Python + Netmiko |
SSH Automation |
Python |
Custom scripts, data collection, troubleshooting |
| NAPALM |
Network Abstraction |
Python |
Multi-vendor config management, getters, config replace |
| Nornir |
Automation Framework |
Python |
Scalable automation (threaded, inventory management) |
| Salt |
Configuration Management |
YAML/Python |
Event-driven automation, real-time (agent-based) |
Ansible for Network
| Feature |
รายละเอียด |
| Agentless |
ไม่ต้อง install agent บน network devices (ใช้ SSH/NETCONF) |
| Playbooks |
YAML files ที่กำหนด tasks (declarative — บอกว่าต้องการอะไร) |
| Modules |
ios_config, nxos_config, junos_config, eos_config (vendor-specific) |
| Inventory |
รายชื่อ devices + variables (hosts, groups, vars) |
| Roles |
Reusable automation components (role per function: base config, SNMP, NTP) |
| Collections |
cisco.ios, junipernetworks.junos, arista.eos (Galaxy collections) |
| AWX/Tower |
Web UI + RBAC + scheduling + logging (enterprise Ansible) |
| Idempotent |
Run playbook หลายรอบ → ผลลัพธ์เหมือนกัน (ไม่ทำซ้ำถ้า config ถูกแล้ว) |
Terraform for Network
| Feature |
รายละเอียด |
| Declarative |
บอกว่า desired state คืออะไร → Terraform หา plan เพื่อไปถึง state นั้น |
| State File |
เก็บ current state → เปรียบเทียบ desired vs current → apply changes |
| Providers |
AWS, Azure, GCP, Cisco ACI, Palo Alto, F5, Infoblox (network providers) |
| Plan |
terraform plan → แสดง changes ก่อน apply (review before making changes) |
| Apply |
terraform apply → execute changes (create, update, destroy resources) |
| Modules |
Reusable infrastructure components (module per service: VPC, subnet, firewall) |
| Best For |
Cloud networking (VPC, subnets, security groups, load balancers) |
Python Netmiko
| Feature |
รายละเอียด |
| คืออะไร |
Python SSH library ที่ simplify การ connect + send commands ไป network devices |
| Multi-Vendor |
Cisco IOS/NX-OS, Juniper, Arista, HP, Dell, Fortinet, Palo Alto, etc. |
| send_command() |
ส่ง show command → return output (สำหรับ data collection) |
| send_config_set() |
ส่ง config commands → enter config mode → apply → exit |
| TextFSM |
Parse unstructured CLI output → structured data (JSON/dict) |
| Use Case |
Custom automation scripts, bulk data collection, troubleshooting tools |
NAPALM
| Feature |
รายละเอียด |
| คืออะไร |
Network Automation and Programmability Abstraction Layer with Multivendor support |
| Getters |
get_facts(), get_interfaces(), get_bgp_neighbors() → structured data (dict) |
| Config Replace |
Replace entire config (atomic — all or nothing) |
| Config Merge |
Merge partial config into running config |
| Compare Config |
compare_config() → show diff before commit |
| Rollback |
discard_config() → rollback if something wrong |
| Supported |
IOS, NX-OS, JunOS, EOS, IOS-XR (via drivers) |
GitOps for Network
| Principle |
รายละเอียด |
| Git as Source of Truth |
ทุก network config อยู่ใน Git repository (version controlled) |
| Pull Request Workflow |
เปลี่ยน config → PR → review → approve → merge → auto-deploy |
| CI/CD Pipeline |
Merge → trigger pipeline → lint → test → deploy to network devices |
| Audit Trail |
Git log = complete history ของทุก change (who, when, what, why) |
| Rollback |
git revert → rollback config change (simple, reliable) |
| Collaboration |
Multiple engineers work on same configs with branching + merging |
Automation Best Practices
| Practice |
รายละเอียด |
| Start Small |
เริ่มจาก read-only tasks (show commands, data collection) → แล้วค่อย config changes |
| Version Control |
ทุก playbook/script/config อยู่ใน Git (ไม่มี local-only files) |
| Test Before Deploy |
Test ใน lab/staging ก่อน production (CI/CD pipeline with testing) |
| Idempotent |
เขียน automation ที่ run ซ้ำได้โดยไม่เกิดปัญหา |
| Inventory Management |
Central inventory (NetBox, CMDB) → single source of truth สำหรับ devices |
| Error Handling |
Handle failures gracefully (retry, rollback, alert — ไม่ใช่ fail silently) |
| Secrets Management |
ไม่ hardcode passwords → ใช้ vault (HashiCorp Vault, Ansible Vault) |
ทิ้งท้าย: Network Automation = CLI is Dead, Long Live Code
Network Automation Ansible: agentless, YAML playbooks, idempotent, multi-vendor (best for config management) Terraform: IaC, state management, declarative, providers (best for cloud networking) Netmiko: Python SSH library, send_command/send_config_set (best for custom scripts) NAPALM: abstraction layer, getters, config replace/merge/diff/rollback (multi-vendor) GitOps: Git as source of truth, PR workflow, CI/CD, audit trail, rollback Best Practice: start small (read-only) → version control → test → idempotent → secrets management
อ่านเพิ่มเติมเกี่ยวกับ Network Monitoring SNMP NetFlow และ Network Packet Analysis Wireshark ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com