Network Automation คืออะไร? สอนใช้ Ansible และ Python จัดการเครือข่ายอัตโนมัติ 2026

บทนำ: ทำไม Network Engineer ต้องเรียนรู้ Automation ในปี 2026?

ในอดีต Network Engineer ทำงานด้วยการ SSH เข้า router/switch ทีละตัว พิมพ์ CLI command ทีละบรรทัด ซึ่งในเครือข่ายที่มีอุปกรณ์ไม่กี่สิบตัวอาจไม่ใช่ปัญหา แต่ในองค์กรขนาดใหญ่ที่มีอุปกรณ์หลายร้อยหลายพันตัว วิธีแบบ manual นี้ช้า ผิดพลาดง่าย และไม่สามารถ scale ได้

Network Automation คือการใช้เครื่องมือและโค้ดในการจัดการเครือข่ายอัตโนมัติ แทนที่จะพิมพ์ command ทีละตัว เราเขียน script หรือ playbook ครั้งเดียว แล้วรันกับอุปกรณ์ทุกตัวพร้อมกัน ลดเวลาทำงานจากหลายชั่วโมงเหลือไม่กี่นาที ลดโอกาสผิดพลาดจาก human error และทำให้ทุก configuration เป็นมาตรฐานเดียวกัน

ในปี 2026 ทักษะ Network Automation ไม่ใช่ “nice to have” อีกต่อไป แต่เป็น ทักษะจำเป็น (must-have) สำหรับ Network Engineer ที่ต้องการเติบโตในสายอาชีพ Cisco เปลี่ยน certification track เพิ่ม DevNet, Juniper มี Junos Automation, Arista มี CloudVision — ทุก vendor เน้น automation ทั้งหมด

บทความนี้จะสอนตั้งแต่พื้นฐาน: ทำไมต้อง automate, เครื่องมือหลัก (Ansible, Python, Nornir), protocol ที่ใช้ (NETCONF, RESTCONF, SSH), ตัวอย่างการใช้งานจริง (config backup, compliance check, VLAN deployment), การทำ CI/CD สำหรับ network, การสร้าง lab สำหรับฝึก และเส้นทาง career

ส่วนที่ 1: ปัญหาของ Traditional Network Management

1.1 CLI-Based Management — ทำงานแบบเดิมๆ

วิธีจัดการเครือข่ายแบบดั้งเดิมมีปัญหาหลายอย่าง:

  • Manual และช้า: ถ้าต้องเปลี่ยน SNMP community string บน switch 200 ตัว ต้อง SSH เข้าทีละตัว พิมพ์ command ทีละบรรทัด อาจใช้เวลาทั้งวัน
  • Human Error: พิมพ์ command ผิดแม้แค่ตัวอักษรเดียวก็อาจทำให้ network ล่มได้ ยิ่งทำซ้ำๆ บนอุปกรณ์เยอะ โอกาสผิดพลาดยิ่งสูง
  • Inconsistency: เมื่อหลายคนดูแลอุปกรณ์คนละกลุ่ม config จะไม่เหมือนกัน — บาง switch ใช้ ACL แบบหนึ่ง บางตัวใช้อีกแบบ
  • ไม่มี Version Control: ไม่มีประวัติว่า “ใครเปลี่ยนอะไร เมื่อไหร่ ทำไม” ถ้าเกิดปัญหาจะ rollback ยาก
  • ไม่ Scalable: เมื่อเครือข่ายโตจาก 50 อุปกรณ์เป็น 500 ตัว จำนวน engineer ที่ต้องการก็เพิ่มตาม

1.2 ตัวอย่างสถานการณ์จริง

สถานการณ์: ต้องเพิ่ม VLAN 100 (Guest WiFi) บน Access Switch 150 ตัว

แบบ Manual:
  - SSH เข้า switch ทีละตัว (150 ครั้ง)
  - พิมพ์: vlan 100 / name Guest_WiFi / exit
  - พิมพ์: interface range gi0/1-24 / switchport trunk allowed vlan add 100
  - เวลาที่ใช้: ~6-8 ชั่วโมง (ถ้าไม่มีปัญหา)
  - โอกาสผิด: สูง (อาจลืม switch บางตัว หรือพิมพ์ VLAN ID ผิด)

แบบ Automation (Ansible):
  - เขียน playbook 1 ไฟล์ (15 นาที)
  - รัน: ansible-playbook deploy_vlan.yml
  - Ansible จะ SSH เข้า switch ทุกตัวพร้อมกัน ส่ง command เหมือนกันทุกตัว
  - เวลาที่ใช้: ~5 นาที (รวมเวลาเขียน playbook)
  - โอกาสผิด: ต่ำมาก (test ก่อน deploy, idempotent)

ส่วนที่ 2: Ansible สำหรับ Network Automation

2.1 Ansible คืออะไร?

Ansible คือ open-source automation tool ที่พัฒนาโดย Red Hat ออกแบบมาให้ใช้งานง่ายที่สุดในบรรดา automation tool ทั้งหมด จุดเด่นหลักคือ:

  • Agentless: ไม่ต้องติดตั้ง software บนอุปกรณ์ที่จะจัดการ — ใช้ SSH (network devices) หรือ WinRM (Windows)
  • ใช้ YAML: เขียน playbook ด้วย YAML ที่อ่านง่าย ไม่ต้องเป็นโปรแกรมเมอร์ก็เขียนได้
  • Idempotent: รันกี่ครั้งก็ได้ผลลัพธ์เหมือนเดิม — ถ้า config ถูกต้องอยู่แล้ว Ansible จะไม่เปลี่ยนแปลงอะไร
  • มี Network Module มากมาย: Cisco IOS, NX-OS, Juniper JunOS, Arista EOS, Palo Alto, F5, etc.

2.2 Ansible Architecture สำหรับ Network

Ansible Architecture:
  ┌───────────────────────────────────────┐
  │         Ansible Control Node          │
  │  (Linux server ที่รัน Ansible)         │
  │                                       │
  │  ┌──────────┐  ┌──────────────────┐   │
  │  │ Inventory│  │ Playbooks (.yml) │   │
  │  │ (hosts)  │  │ Tasks, Roles     │   │
  │  └──────────┘  └──────────────────┘   │
  └────────────┬──────────────────────────┘
               │ SSH / NETCONF / API
    ┌──────────┼──────────────────────────┐
    │          │                          │
  ┌─▼──┐   ┌──▼─┐   ┌─────┐   ┌──────┐
  │ R1 │   │ R2 │   │ SW1 │   │ FW1  │
  │Cisco│  │Junos│  │Arista│  │PaloA │
  └────┘   └────┘   └─────┘   └──────┘

  * Control Node: เครื่องที่รัน Ansible (ต้องเป็น Linux)
  * Managed Nodes: อุปกรณ์ที่ถูกจัดการ (router/switch/firewall)
  * ไม่ต้องติดตั้ง agent บน managed nodes

2.3 Ansible Inventory — รายการอุปกรณ์

Inventory คือไฟล์ที่ระบุว่ามีอุปกรณ์อะไรบ้าง จัดกลุ่มอย่างไร และ credentials สำหรับเชื่อมต่อ:

# inventory.yml
all:
  children:
    core_routers:
      hosts:
        core-r1:
          ansible_host: 10.0.0.1
          ansible_network_os: cisco.ios.ios
        core-r2:
          ansible_host: 10.0.0.2
          ansible_network_os: cisco.ios.ios
    access_switches:
      hosts:
        acc-sw01:
          ansible_host: 10.0.1.1
          ansible_network_os: cisco.ios.ios
        acc-sw02:
          ansible_host: 10.0.1.2
          ansible_network_os: cisco.ios.ios
        acc-sw03:
          ansible_host: 10.0.1.3
          ansible_network_os: cisco.ios.ios
    firewalls:
      hosts:
        fw-01:
          ansible_host: 10.0.0.10
          ansible_network_os: paloaltonetworks.panos.panos
  vars:
    ansible_user: admin
    ansible_password: "{{ vault_password }}"
    ansible_connection: ansible.netcommon.network_cli

2.4 Ansible Playbook — สคริปต์อัตโนมัติ

Playbook คือไฟล์ YAML ที่กำหนดว่าจะทำอะไรกับอุปกรณ์ไหน:

ตัวอย่างที่ 1: Backup Running Config ของ Router ทุกตัว

# backup_config.yml
---
- name: Backup running configuration
  hosts: core_routers
  gather_facts: no

  tasks:
    - name: Get running config
      cisco.ios.ios_command:
        commands:
          - show running-config
      register: config_output

    - name: Save config to file
      copy:
        content: "{{ config_output.stdout[0] }}"
        dest: "./backups/{{ inventory_hostname }}_{{ ansible_date_time.date }}.cfg"
      delegate_to: localhost

    - name: Display backup status
      debug:
        msg: "Backup completed for {{ inventory_hostname }}"

ตัวอย่างที่ 2: Deploy VLAN บน Access Switch ทุกตัว

# deploy_vlan.yml
---
- name: Deploy Guest VLAN to all access switches
  hosts: access_switches
  gather_facts: no

  vars:
    vlan_id: 100
    vlan_name: Guest_WiFi

  tasks:
    - name: Create VLAN
      cisco.ios.ios_vlans:
        config:
          - vlan_id: "{{ vlan_id }}"
            name: "{{ vlan_name }}"
            state: active
        state: merged

    - name: Add VLAN to trunk ports
      cisco.ios.ios_config:
        lines:
          - switchport trunk allowed vlan add {{ vlan_id }}
        parents: interface range GigabitEthernet0/1-24

    - name: Save configuration
      cisco.ios.ios_config:
        save_when: modified

    - name: Verify VLAN exists
      cisco.ios.ios_command:
        commands:
          - show vlan id {{ vlan_id }}
      register: vlan_check

    - name: Display result
      debug:
        msg: "{{ vlan_check.stdout_lines }}"

ตัวอย่างที่ 3: Compliance Check — ตรวจสอบว่า Config ตรงมาตรฐาน

# compliance_check.yml
---
- name: Network Compliance Check
  hosts: all
  gather_facts: no

  tasks:
    - name: Check NTP configuration
      cisco.ios.ios_command:
        commands:
          - show running-config | include ntp server
      register: ntp_config

    - name: Verify NTP server is correct
      assert:
        that:
          - "'ntp server 10.0.0.100' in ntp_config.stdout[0]"
        fail_msg: "NTP server incorrect on {{ inventory_hostname }}"
        success_msg: "NTP OK on {{ inventory_hostname }}"

    - name: Check SSH version 2
      cisco.ios.ios_command:
        commands:
          - show ip ssh
      register: ssh_config

    - name: Verify SSH version 2
      assert:
        that:
          - "'SSH Enabled - version 2' in ssh_config.stdout[0]"
        fail_msg: "SSH v2 not enabled on {{ inventory_hostname }}"
        success_msg: "SSH v2 OK on {{ inventory_hostname }}"

    - name: Check banner
      cisco.ios.ios_command:
        commands:
          - show running-config | include banner
      register: banner_config

    - name: Verify login banner exists
      assert:
        that:
          - "'banner login' in banner_config.stdout[0]"
        fail_msg: "Login banner missing on {{ inventory_hostname }}"
        success_msg: "Banner OK on {{ inventory_hostname }}"

2.5 Ansible Network Modules ที่สำคัญ

Module                    | ใช้กับ      | หน้าที่
--------------------------|------------|----------------------------------
cisco.ios.ios_config      | Cisco IOS  | ส่ง configuration commands
cisco.ios.ios_command     | Cisco IOS  | ส่ง show commands
cisco.ios.ios_vlans       | Cisco IOS  | จัดการ VLANs
cisco.ios.ios_interfaces  | Cisco IOS  | จัดการ interfaces
cisco.nxos.nxos_config    | Cisco NX-OS| จัดการ Nexus switches
junipernetworks.junos.*   | Juniper    | จัดการ Junos devices
arista.eos.eos_config     | Arista EOS | จัดการ Arista switches
ansible.netcommon.cli_*   | ทุก vendor | Generic CLI operations
ansible.netcommon.netconf_*| NETCONF   | NETCONF operations

2.6 Ansible Vault — เก็บ Password ปลอดภัย

ไม่ควรเก็บ password แบบ plain text ใน inventory ให้ใช้ Ansible Vault เข้ารหัส:

# สร้าง encrypted password file
ansible-vault create group_vars/all/vault.yml

# เนื้อหาใน vault.yml (ก่อนเข้ารหัส)
vault_password: "SecureP@ss123"
vault_enable_password: "Enable@123"

# รัน playbook พร้อม vault
ansible-playbook -i inventory.yml backup_config.yml --ask-vault-pass

# หรือใช้ vault password file
ansible-playbook -i inventory.yml backup_config.yml --vault-password-file ~/.vault_pass

ส่วนที่ 3: Python สำหรับ Network Automation

3.1 ทำไมต้อง Python?

Python เป็นภาษาที่ได้รับความนิยมสูงสุดสำหรับ Network Automation เพราะ:

  • เรียนรู้ง่าย — syntax อ่านง่ายเหมือนภาษาอังกฤษ
  • มี library สำหรับ network มากมาย (netmiko, paramiko, napalm, nornir, pyats)
  • ใช้ได้ทั้ง scripting (automation) และ programming (สร้าง tool)
  • Cisco DevNet, Juniper, Arista ล้วนรองรับ Python
  • community ใหญ่ มีตัวอย่าง code เยอะ

3.2 Netmiko — SSH สำหรับ Network Devices

Netmiko คือ Python library ที่ทำให้ SSH เข้า network devices ง่ายขึ้น รองรับ vendor หลายสิบรายการ:

# ติดตั้ง
pip install netmiko

# ตัวอย่าง: SSH เข้า Cisco switch แล้วดึง running config
from netmiko import ConnectHandler

device = {
    'device_type': 'cisco_ios',
    'host': '10.0.1.1',
    'username': 'admin',
    'password': 'password123',
    'secret': 'enable123',  # enable password
}

# เชื่อมต่อ
net_connect = ConnectHandler(**device)
net_connect.enable()  # เข้า enable mode

# ส่ง show command
output = net_connect.send_command('show ip interface brief')
print(output)

# ส่ง configuration commands
config_commands = [
    'interface Loopback99',
    'description Automation_Test',
    'ip address 10.99.99.1 255.255.255.0',
    'no shutdown',
]
output = net_connect.send_config_set(config_commands)
print(output)

# Save config
net_connect.save_config()

# ปิดการเชื่อมต่อ
net_connect.disconnect()

ตัวอย่าง: Backup Config จาก Switch หลายตัว

from netmiko import ConnectHandler
from datetime import datetime
import os

# รายการ switch
switches = [
    {'device_type': 'cisco_ios', 'host': '10.0.1.1', 'username': 'admin', 'password': 'pass'},
    {'device_type': 'cisco_ios', 'host': '10.0.1.2', 'username': 'admin', 'password': 'pass'},
    {'device_type': 'cisco_ios', 'host': '10.0.1.3', 'username': 'admin', 'password': 'pass'},
]

# สร้าง folder สำหรับ backup
backup_dir = f"backups/{datetime.now().strftime('%Y-%m-%d')}"
os.makedirs(backup_dir, exist_ok=True)

for sw in switches:
    try:
        print(f"Connecting to {sw['host']}...")
        conn = ConnectHandler(**sw)
        conn.enable()

        # ดึง hostname
        hostname = conn.send_command('show run | include hostname').split()[-1]

        # ดึง running config
        config = conn.send_command('show running-config')

        # บันทึกไฟล์
        filename = f"{backup_dir}/{hostname}_{sw['host']}.cfg"
        with open(filename, 'w') as f:
            f.write(config)
        print(f"  Saved: {filename}")

        conn.disconnect()
    except Exception as e:
        print(f"  Error on {sw['host']}: {e}")

3.3 Paramiko — SSH ระดับ Low-Level

Paramiko คือ Python library สำหรับ SSH ระดับ low-level ที่ Netmiko สร้างอยู่บน:

import paramiko
import time

# สร้าง SSH connection
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.0.1.1', username='admin', password='password123')

# เปิด interactive shell
shell = ssh.invoke_shell()
time.sleep(1)

# ส่ง command
shell.send('enable\n')
time.sleep(1)
shell.send('enable_password\n')
time.sleep(1)
shell.send('show ip interface brief\n')
time.sleep(2)

# อ่าน output
output = shell.recv(65535).decode('utf-8')
print(output)

ssh.close()

เมื่อไหร่ใช้ Paramiko แทน Netmiko?

  • อุปกรณ์ที่ Netmiko ไม่รองรับ (เช่น อุปกรณ์เก่าหรือ vendor เล็กๆ)
  • ต้องการ control ระดับ low-level มากขึ้น (เช่น SFTP, port forwarding)
  • ต้องการ performance สูงสุด (ลด overhead ของ Netmiko)

3.4 NAPALM — Network Automation and Programmability Abstraction Layer

NAPALM คือ library ที่ให้ unified API สำหรับหลาย vendor — เขียน code เดียวใช้ได้กับ Cisco, Juniper, Arista, etc.:

# ติดตั้ง
pip install napalm

from napalm import get_network_driver

# เชื่อมต่อ Cisco IOS
driver = get_network_driver('ios')
device = driver('10.0.1.1', 'admin', 'password123')
device.open()

# ดึงข้อมูล (unified API — ทุก vendor ใช้ method เดียวกัน)
facts = device.get_facts()
print(f"Hostname: {facts['hostname']}")
print(f"Model: {facts['model']}")
print(f"OS Version: {facts['os_version']}")
print(f"Uptime: {facts['uptime']} seconds")

# ดึง interface info
interfaces = device.get_interfaces()
for name, info in interfaces.items():
    print(f"{name}: {'up' if info['is_up'] else 'down'} | Speed: {info['speed']}")

# ดึง ARP table
arp = device.get_arp_table()
for entry in arp:
    print(f"IP: {entry['ip']} | MAC: {entry['mac']} | Interface: {entry['interface']}")

# เปลี่ยน config (merge)
device.load_merge_candidate(config='interface Loopback99\n description NAPALM_Test')

# ดู diff ก่อน commit
print(device.compare_config())

# Commit หรือ Discard
device.commit_config()    # apply changes
# device.discard_config()  # ยกเลิก

device.close()

จุดเด่นของ NAPALM:

  • Vendor-Agnostic: เขียน code ครั้งเดียว ใช้ได้กับ Cisco IOS, IOS-XR, NX-OS, Juniper JunOS, Arista EOS, etc.
  • Configuration Replace/Merge: สามารถ replace config ทั้งหมด หรือ merge เฉพาะส่วนที่เปลี่ยน
  • Config Diff: compare_config() แสดงให้เห็นว่าจะเปลี่ยนอะไรก่อน commit
  • Rollback: สามารถ rollback_config() กลับไปก่อน commit ได้
  • Getters: get_facts(), get_interfaces(), get_bgp_neighbors(), get_route_to() ฯลฯ

ส่วนที่ 4: NETCONF, YANG และ RESTCONF

4.1 ปัญหาของ CLI-based Automation

แม้ Netmiko/Paramiko จะช่วยให้ SSH เข้าอุปกรณ์ได้ แต่ยังมีปัญหาพื้นฐาน:

  • Screen Scraping: ต้อง parse output ที่เป็น text ซึ่ง format อาจเปลี่ยนแปลงเมื่อ upgrade firmware
  • ไม่มี Transaction: ส่ง command ทีละบรรทัด ถ้าบรรทัดที่ 3 error บรรทัด 1-2 ถูก apply ไปแล้ว
  • ไม่มี Validation: ไม่มีวิธี validate config ก่อน apply

NETCONF และ RESTCONF ถูกออกแบบมาเพื่อแก้ปัญหาเหล่านี้

4.2 NETCONF (Network Configuration Protocol)

NETCONF เป็น protocol มาตรฐาน (RFC 6241) สำหรับจัดการ config อุปกรณ์ network:

  • ใช้ XML เป็น data format — structured data ไม่ต้อง parse text
  • ทำงานผ่าน SSH (port 830)
  • รองรับ Transaction: commit/rollback — ถ้า config มี error จะไม่ apply อะไรเลย
  • รองรับ Candidate Config: แก้ config ใน “staging area” ก่อน แล้วค่อย commit ทีเดียว
  • ใช้ YANG data models กำหนดโครงสร้างของ config
# Python + ncclient สำหรับ NETCONF
pip install ncclient

from ncclient import manager

# เชื่อมต่อผ่าน NETCONF
m = manager.connect(
    host='10.0.1.1',
    port=830,
    username='admin',
    password='password123',
    hostkey_verify=False,
    device_params={'name': 'iosxe'}
)

# ดึง running config (XML format)
config = m.get_config(source='running')
print(config.xml)

# ดึงเฉพาะ interface config ด้วย filter
filter_xml = '''
<filter>
  <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
    <interface>
      <GigabitEthernet>
        <name>1</name>
      </GigabitEthernet>
    </interface>
  </native>
</filter>
'''
result = m.get_config(source='running', filter=filter_xml)
print(result.xml)

# เปลี่ยน config ด้วย edit-config
new_config = '''
<config>
  <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
    <interface>
      <Loopback>
        <name>99</name>
        <description>NETCONF_Test</description>
        <ip>
          <address>
            <primary>
              <address>10.99.99.1</address>
              <mask>255.255.255.0</mask>
            </primary>
          </address>
        </ip>
      </Loopback>
    </interface>
  </native>
</config>
'''
m.edit_config(target='running', config=new_config)
m.close_session()

4.3 YANG Data Models

YANG (Yet Another Next Generation) คือภาษาสำหรับกำหนด โครงสร้างข้อมูล ของอุปกรณ์ network — เหมือน “schema” ของ database:

  • กำหนดว่า config มี field อะไรบ้าง, type อะไร, ค่าที่ valid คืออะไร
  • มีทั้ง vendor-specific models (Cisco-IOS-XE-native, Juniper) และ standard models (OpenConfig, IETF)
  • OpenConfig: โมเดลมาตรฐานที่ใช้ได้กับทุก vendor — เขียน automation ครั้งเดียว ใช้ได้ทุกยี่ห้อ
ตัวอย่าง YANG model สำหรับ interface:
module openconfig-interfaces {
  container interfaces {
    list interface {
      key "name";
      leaf name { type string; }
      container config {
        leaf description { type string; }
        leaf enabled { type boolean; }
        leaf mtu { type uint16; }
      }
      container state {
        leaf oper-status { type enumeration { enum UP; enum DOWN; } }
        leaf admin-status { type enumeration { enum UP; enum DOWN; } }
      }
    }
  }
}

4.4 RESTCONF

RESTCONF คือ protocol ที่ให้ REST API (HTTP) สำหรับจัดการ config อุปกรณ์ — ใช้ YANG model เดียวกับ NETCONF แต่เข้าถึงผ่าน HTTP GET/POST/PUT/PATCH/DELETE:

# ตัวอย่าง RESTCONF ด้วย Python requests
import requests
import json

BASE_URL = "https://10.0.1.1/restconf"
HEADERS = {
    "Accept": "application/yang-data+json",
    "Content-Type": "application/yang-data+json"
}
AUTH = ("admin", "password123")

# GET — ดึง interface list
url = f"{BASE_URL}/data/ietf-interfaces:interfaces"
r = requests.get(url, headers=HEADERS, auth=AUTH, verify=False)
interfaces = r.json()
for intf in interfaces['ietf-interfaces:interfaces']['interface']:
    print(f"{intf['name']}: {intf.get('description', 'N/A')}")

# PUT — สร้างหรือแก้ interface
url = f"{BASE_URL}/data/ietf-interfaces:interfaces/interface=Loopback99"
payload = {
    "ietf-interfaces:interface": {
        "name": "Loopback99",
        "description": "RESTCONF_Test",
        "type": "iana-if-type:softwareLoopback",
        "enabled": True,
        "ietf-ip:ipv4": {
            "address": [{"ip": "10.99.99.1", "netmask": "255.255.255.0"}]
        }
    }
}
r = requests.put(url, headers=HEADERS, auth=AUTH, json=payload, verify=False)
print(f"Status: {r.status_code}")  # 201=Created, 204=Updated

# DELETE — ลบ interface
r = requests.delete(url, headers=HEADERS, auth=AUTH, verify=False)
print(f"Deleted: {r.status_code}")

ส่วนที่ 5: Nornir Framework

5.1 Nornir คืออะไร?

Nornir คือ Python automation framework ที่ออกแบบมาสำหรับ network automation โดยเฉพาะ แตกต่างจาก Ansible ตรงที่ Nornir เป็น pure Python — ไม่ต้องเรียนรู้ YAML syntax ใหม่ ใช้ Python ที่รู้อยู่แล้วได้เลย:

  • Multithreaded: รัน task กับหลายอุปกรณ์พร้อมกัน (parallel execution)
  • Plugin-based: ใช้ร่วมกับ Netmiko, NAPALM, Paramiko, Scrapli ได้
  • Inventory: รองรับ YAML, SimpleInventory, NetBox, Ansible inventory
  • Programmatic: เป็น Python library ไม่ใช่ CLI tool — สร้าง custom logic ได้ง่าย
# ติดตั้ง
pip install nornir nornir_netmiko nornir_utils

# config.yaml
---
inventory:
  plugin: SimpleInventory
  options:
    host_file: "hosts.yaml"
    group_file: "groups.yaml"
    defaults_file: "defaults.yaml"
runner:
  plugin: threaded
  options:
    num_workers: 20  # รัน 20 อุปกรณ์พร้อมกัน

# hosts.yaml
---
core-r1:
  hostname: 10.0.0.1
  groups:
    - cisco_ios
core-r2:
  hostname: 10.0.0.2
  groups:
    - cisco_ios
acc-sw01:
  hostname: 10.0.1.1
  groups:
    - cisco_ios

# Python script
from nornir import InitNornir
from nornir_netmiko.tasks import netmiko_send_command, netmiko_send_config
from nornir_utils.plugins.functions import print_result

# สร้าง Nornir instance
nr = InitNornir(config_file="config.yaml")

# รัน show command กับทุกอุปกรณ์ (parallel)
result = nr.run(task=netmiko_send_command, command_string="show version")
print_result(result)

# Filter เฉพาะ group
access = nr.filter(groups__contains="access_switches")
result = access.run(task=netmiko_send_config,
                     config_commands=["vlan 100", "name Guest_WiFi"])
print_result(result)

5.2 Nornir vs Ansible — เลือกอะไรดี?

คุณสมบัติ         | Ansible              | Nornir
-----------------|----------------------|---------------------
ภาษา             | YAML (Playbooks)     | Python
Learning Curve   | ง่ายกว่า              | ต้องรู้ Python
Flexibility      | จำกัดโดย module       | ไม่จำกัด (pure Python)
Performance      | ปานกลาง              | เร็วกว่า (threaded)
Debugging        | ยาก                  | ง่าย (Python debugger)
Community        | ใหญ่มาก              | เล็กกว่า
Enterprise       | Ansible Tower/AWX    | ต้องสร้างเอง
เหมาะกับ         | Ops/Network Engineer | Developer/DevNet

ส่วนที่ 6: Network Automation Use Cases

6.1 Configuration Backup and Restore

Use case พื้นฐานที่สุดแต่สำคัญที่สุด:

  • ตั้ง cron job ให้ Ansible/Python backup running config ของอุปกรณ์ทุกตัวทุกวัน
  • เก็บ backup ใน Git repository — ได้ version history ฟรี
  • ตั้ง alert ถ้า config เปลี่ยนแปลง (config drift detection)
  • สามารถ restore config จาก Git ได้ทุกเมื่อ

6.2 Compliance Checking

ตรวจสอบว่า config ของอุปกรณ์ทุกตัวเป็นไปตามมาตรฐานที่กำหนด:

  • ตรวจสอบว่า NTP server ถูกต้อง
  • ตรวจสอบว่า SSH version 2 เปิดอยู่
  • ตรวจสอบว่า SNMP community string ไม่ใช่ “public”
  • ตรวจสอบว่า password encryption เปิดอยู่
  • ตรวจสอบว่า login banner มีข้อความตามกฎหมาย
  • ตรวจสอบว่า unused ports ถูก shutdown
  • รัน compliance check ทุกวัน แล้ว report ผลลัพธ์ให้ทีม security

6.3 Bulk Configuration Changes

การเปลี่ยน config จำนวนมากพร้อมกัน:

  • Deploy VLAN ใหม่บน switch ทุกตัว
  • เปลี่ยน SNMP community string ทุกอุปกรณ์
  • Update ACL บน router ทุกตัว
  • เปลี่ยน syslog server address
  • Deploy QoS policy บน WAN router

6.4 Network Inventory and Documentation

ดึงข้อมูลจากอุปกรณ์ทุกตัวเพื่อสร้าง inventory อัตโนมัติ:

# สร้าง network inventory อัตโนมัติ
from napalm import get_network_driver
import csv

devices = [
    {'host': '10.0.1.1', 'type': 'ios'},
    {'host': '10.0.1.2', 'type': 'ios'},
    {'host': '10.0.0.1', 'type': 'junos'},
]

inventory = []
for d in devices:
    driver = get_network_driver(d['type'])
    dev = driver(d['host'], 'admin', 'password')
    dev.open()

    facts = dev.get_facts()
    inventory.append({
        'hostname': facts['hostname'],
        'ip': d['host'],
        'vendor': facts['vendor'],
        'model': facts['model'],
        'os_version': facts['os_version'],
        'serial': facts['serial_number'],
        'uptime_days': facts['uptime'] // 86400,
    })
    dev.close()

# Export เป็น CSV
with open('network_inventory.csv', 'w', newline='') as f:
    writer = csv.DictWriter(f, fieldnames=inventory[0].keys())
    writer.writeheader()
    writer.writerows(inventory)
print(f"Inventory saved: {len(inventory)} devices")

ส่วนที่ 7: Git สำหรับ Network Configuration

7.1 ทำไมต้องใช้ Git กับ Network?

Git ให้ประโยชน์มหาศาลเมื่อใช้กับ network configuration:

  • Version History: ดูได้ว่า config เปลี่ยนแปลงอะไร เมื่อไหร่ ใครเปลี่ยน
  • Diff: เปรียบเทียบ config ก่อน-หลังเปลี่ยนได้ง่าย
  • Rollback: กลับไปใช้ config เวอร์ชันก่อนหน้าได้ทุกเมื่อ
  • Branching: ทดลองเปลี่ยน config ใน branch แยก ก่อน merge เข้า production
  • Code Review: ใช้ Pull Request ให้คนอื่น review config ก่อน deploy
  • Audit Trail: commit history เป็น audit log ที่สมบูรณ์

7.2 Git Workflow สำหรับ Network

Network Configuration Git Workflow:

  1. Engineer สร้าง branch ใหม่:
     git checkout -b feature/add-guest-vlan

  2. แก้ playbook / config template:
     แก้ไฟล์ deploy_vlan.yml, inventory.yml

  3. Test ใน lab (GNS3/EVE-NG):
     ansible-playbook -i lab_inventory.yml deploy_vlan.yml --check

  4. Commit และ push:
     git add . && git commit -m "Add Guest VLAN 100"
     git push origin feature/add-guest-vlan

  5. สร้าง Pull Request → ให้ senior engineer review

  6. หลัง approve → merge เข้า main

  7. CI/CD pipeline รัน playbook กับ production อัตโนมัติ:
     ansible-playbook -i production_inventory.yml deploy_vlan.yml

ส่วนที่ 8: CI/CD สำหรับ Network Automation

8.1 CI/CD Pipeline คืออะไร?

CI/CD (Continuous Integration / Continuous Deployment) คือ process ที่ทำให้การ deploy configuration เป็นอัตโนมัติ ตั้งแต่ code commit จนถึง production deployment:

CI/CD Pipeline สำหรับ Network:

  ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐
  │  Commit  │───►│  Lint &  │───►│ Test in  │───►│ Deploy   │
  │  Code    │    │  Syntax  │    │   Lab    │    │ to Prod  │
  │  (Git)   │    │  Check   │    │ (GNS3)  │    │ (Ansible)│
  └──────────┘    └──────────┘    └──────────┘    └──────────┘
      │              │                │                │
      │          yamllint          ansible-playbook   ansible-playbook
      │          ansible-lint      --check --diff     (production)
      │                           (lab inventory)
      │
  ┌──────────┐
  │ Notify   │
  │ (Slack,  │
  │  Teams)  │
  └──────────┘

8.2 ตัวอย่าง GitLab CI/CD Pipeline

# .gitlab-ci.yml
stages:
  - lint
  - test
  - deploy

lint:
  stage: lint
  script:
    - pip install yamllint ansible-lint
    - yamllint playbooks/
    - ansible-lint playbooks/*.yml

test_in_lab:
  stage: test
  script:
    - ansible-playbook -i inventories/lab/hosts.yml playbooks/deploy_vlan.yml --check --diff
  when: manual

deploy_production:
  stage: deploy
  script:
    - ansible-playbook -i inventories/production/hosts.yml playbooks/deploy_vlan.yml --diff
  when: manual
  only:
    - main
  environment:
    name: production

ส่วนที่ 9: สร้าง Automation Lab

9.1 GNS3 — Network Emulator

GNS3 เป็น network emulator ที่ใช้ IOS image จริง:

  • รัน Cisco IOS, IOS-XR, NX-OS (ต้องมี license/image)
  • รัน Juniper vSRX, Arista vEOS (free)
  • เชื่อมต่อกับ network จริงได้ (cloud node)
  • รันบน PC ได้ แต่แนะนำ GNS3 VM server สำหรับ performance
  • ข้อดี: ใช้ IOS จริง ผลลัพธ์เหมือน production
  • ข้อเสีย: ต้องมี IOS image (license), ใช้ RAM มาก

9.2 EVE-NG — Enterprise Virtual Environment

EVE-NG เป็นทางเลือกของ GNS3 ที่ทำงานเป็น web-based:

  • รันเป็น VM บน VMware/VirtualBox หรือ bare-metal
  • จัดการ lab ผ่าน web browser — ไม่ต้องติดตั้ง client
  • รองรับ QEMU, Dynamips, Docker — ใช้ image ได้หลายแบบ
  • Community Edition ฟรี, Professional Edition มี feature เพิ่ม

9.3 Containerlab — สำหรับ Modern Network Lab

Containerlab เป็น tool ใหม่ที่ใช้ container สำหรับ network lab:

  • ใช้ Docker container แทน VM — เบากว่า เร็วกว่า
  • รองรับ Nokia SR Linux, Arista cEOS, Cisco XRd, Juniper cRPD (containerized)
  • สร้าง topology ด้วย YAML ไฟล์เดียว
  • เหมาะกับ CI/CD pipeline — สร้าง lab อัตโนมัติ ทดสอบ แล้วทำลาย
# containerlab topology file
name: automation-lab
topology:
  nodes:
    spine1:
      kind: ceos
      image: arista/ceos:4.30.0F
    spine2:
      kind: ceos
      image: arista/ceos:4.30.0F
    leaf1:
      kind: ceos
      image: arista/ceos:4.30.0F
    leaf2:
      kind: ceos
      image: arista/ceos:4.30.0F
  links:
    - endpoints: ["spine1:eth1", "leaf1:eth1"]
    - endpoints: ["spine1:eth2", "leaf2:eth1"]
    - endpoints: ["spine2:eth1", "leaf1:eth2"]
    - endpoints: ["spine2:eth2", "leaf2:eth2"]

# Deploy lab
containerlab deploy -t lab.yml

# Destroy lab
containerlab destroy -t lab.yml

ส่วนที่ 10: Automation Best Practices

10.1 เริ่มต้นจากสิ่งง่ายๆ

  • เริ่มจาก read-only automation ก่อน: backup config, collect show commands, สร้าง inventory
  • ค่อยๆ ขยับไป write automation: deploy VLAN, update ACL, change NTP
  • ใช้ –check mode (dry run) เสมอก่อน deploy จริง
  • อย่าพยายาม automate ทุกอย่างพร้อมกัน — ทำทีละ use case

10.2 Testing Strategy

  • Lint: ตรวจสอบ syntax ของ YAML, Python ก่อน commit
  • Dry Run: ใช้ –check –diff เพื่อดูว่าจะเปลี่ยนอะไร โดยไม่ apply จริง
  • Lab Test: ทดสอบใน GNS3/EVE-NG/Containerlab ก่อน production เสมอ
  • Canary Deploy: deploy กับอุปกรณ์ 1-2 ตัวก่อน ถ้าผ่านค่อย deploy ทั้งหมด
  • Rollback Plan: เตรียม playbook สำหรับ rollback ไว้เสมอ

10.3 Documentation and Structure

โครงสร้าง project ที่แนะนำ:
network-automation/
├── ansible.cfg
├── inventories/
│   ├── production/
│   │   ├── hosts.yml
│   │   ├── group_vars/
│   │   │   ├── all/
│   │   │   │   ├── vars.yml
│   │   │   │   └── vault.yml (encrypted)
│   │   │   ├── core_routers.yml
│   │   │   └── access_switches.yml
│   │   └── host_vars/
│   │       ├── core-r1.yml
│   │       └── core-r2.yml
│   └── lab/
│       └── hosts.yml
├── playbooks/
│   ├── backup_config.yml
│   ├── deploy_vlan.yml
│   ├── compliance_check.yml
│   └── update_ntp.yml
├── roles/
│   ├── base_config/
│   ├── vlan_management/
│   └── security_hardening/
├── templates/
│   ├── base_config.j2
│   └── acl_template.j2
├── scripts/
│   ├── backup_all.py
│   └── inventory_report.py
├── .gitlab-ci.yml
└── README.md

10.4 Security Considerations

  • ใช้ Ansible Vault หรือ HashiCorp Vault สำหรับเก็บ credentials — ไม่เก็บ password ใน plain text
  • ใช้ SSH keys แทน password เมื่อทำได้
  • จำกัด least privilege — automation account มีสิทธิ์เฉพาะที่จำเป็น
  • เปิด logging ทุก automation task — ต้องรู้ว่า automation ทำอะไรไปบ้าง
  • ใช้ RBAC ใน Ansible Tower/AWX — ควบคุมว่าใครรันอะไรได้
  • เข้ารหัส Git repository ที่เก็บ network config — อาจมีข้อมูล sensitive

ส่วนที่ 11: เส้นทางอาชีพ — DevNet Certification

11.1 Cisco DevNet Certification Track

Cisco สร้าง certification track ใหม่ชื่อ DevNet สำหรับ network automation:

DevNet Certification Path:
  ┌──────────────────────────┐
  │ DevNet Associate          │  ← Entry level
  │ - Python basics           │
  │ - REST API                │
  │ - Cisco APIs (Meraki, DNA)│
  │ - Basic automation        │
  └────────────┬──────────────┘
               │
  ┌────────────▼──────────────┐
  │ DevNet Professional       │  ← Mid level
  │ - Advanced automation     │
  │ - CI/CD for network       │
  │ - YANG/NETCONF/RESTCONF   │
  │ - Application development │
  └────────────┬──────────────┘
               │
  ┌────────────▼──────────────┐
  │ DevNet Expert (new 2024)  │  ← Expert level (lab exam)
  │ - Complex automation      │
  │ - Full stack NetDevOps    │
  │ - Architecture design     │
  └───────────────────────────┘

11.2 ทักษะที่ต้องมีสำหรับ Network Automation Engineer

  • Networking: CCNA level ขึ้นไป — ต้องเข้าใจ network ก่อน automate ได้
  • Python: ระดับ intermediate — เขียน script, ใช้ library, handle errors
  • Linux: ใช้ command line, จัดการ file, cron, systemd
  • Ansible: เขียน playbook, role, template (Jinja2)
  • Git: branch, merge, pull request, resolve conflicts
  • API: REST API, JSON/XML, authentication methods
  • NETCONF/YANG: สำหรับ modern network devices
  • Docker/Containers: สำหรับ lab และ CI/CD
  • CI/CD: GitLab CI, Jenkins, GitHub Actions

11.3 เงินเดือน Network Automation Engineer (ไทย 2026)

ตำแหน่ง                      | เงินเดือน (บาท/เดือน)
-----------------------------|----------------------
Junior Network Engineer      | 25,000 - 40,000
Network Engineer             | 40,000 - 65,000
Sr. Network Engineer         | 65,000 - 100,000
Network Automation Engineer  | 70,000 - 120,000
DevNet / NetDevOps Engineer  | 80,000 - 150,000
Network Architect            | 100,000 - 200,000+

* Network Automation skills เพิ่มเงินเดือนได้ 20-50% เมื่อเทียบกับ
  Network Engineer ที่ทำงานแบบ manual อย่างเดียว

สรุป: Network Automation ในปี 2026

Network Automation ไม่ใช่อนาคตอีกต่อไป แต่เป็นปัจจุบัน องค์กรที่ยังจัดการ network แบบ manual กำลังตกยุค เพราะ:

  • ความซับซ้อนเพิ่มขึ้น: SD-WAN, Multi-cloud, Zero Trust ทำให้ config ซับซ้อนขึ้นมาก manual ไม่ไหว
  • ความเร็วในการ deploy: Business ต้องการ change ภายในนาที ไม่ใช่ชั่วโมงหรือวัน
  • Consistency: automation ให้ config ที่เหมือนกันทุกตัว ลด human error
  • Compliance: automation ตรวจสอบ compliance ได้อัตโนมัติ ไม่ต้องรอ audit

ขั้นตอนแรกที่แนะนำ:

  1. เรียน Python พื้นฐาน (Codecademy, Automate the Boring Stuff)
  2. ติดตั้ง GNS3 หรือ EVE-NG สร้าง lab
  3. ลอง Netmiko SSH เข้า router ใน lab
  4. เรียนรู้ Ansible เขียน playbook backup config
  5. ใส่ config ใน Git ฝึก version control
  6. ลอง NETCONF/RESTCONF กับ Cisco IOS-XE
  7. สร้าง CI/CD pipeline ด้วย GitLab CI
  8. สอบ Cisco DevNet Associate

จำไว้ว่า: Network Automation ไม่ได้มาแทนที่ Network Engineer แต่มาช่วยให้ Network Engineer ทำงานได้ดีขึ้น เร็วขึ้น และมีคุณค่ามากขึ้น คนที่เรียนรู้ automation จะเป็น “10x Network Engineer” ที่ทำงานได้มากกว่าคนที่ทำ manual แบบเดิม 10 เท่า

.

.
.
.

จัดส่งรวดเร็วส่งด่วนทั่วประเทศ
รับประกันสินค้าเคลมง่าย มีใบรับประกัน
ผ่อนชำระได้บัตรเครดิต 0% สูงสุด 10 เดือน
สะสมแต้ม รับส่วนลดส่วนลดและคะแนนสะสม

© 2026 SiamLancard — จำหน่ายการ์ดแลน อุปกรณ์ Server และเครื่องพิมพ์ใบเสร็จ

SiamLancard
#ffffff
Free Forex EA — XM Signal · SiamCafe Blog · SiamLancard · Siam2R · iCafeFX
Partner Sites: iCafe Forex | SiamCafe | SiamLancard | Siam2R | XM Signal | iCafe Cloud
iCafeForex.com - สอนเทรด Forex | SiamCafe.net
Shopping cart
Partner Sites: iCafeForex | SiamCafe | Siam2R | XMSignal