Communitygithub.com

Netmiko SSH 자동화

안전한 Python Netmiko 패턴을 제공하여 읽기 전용 수집, 제한된 배치 SSH, TextFSM 파싱, 보호된 설정 변경, 타임아웃 및 네트워크 자동화 오류 처리를 지원합니다. Python Netmiko로 네트워크 장치 접근을 자동화할 때 사용하며, 상태 수집 또는 보호된 설정 변경 모두에 적합합니다.

Netmiko SSH 자동화란 무엇인가요?

이 스킬은 Netmiko를 사용한 네트워크 장치 SSH 자동화에서 안전하고 효율적인 패턴을 제공합니다. 기본 경로는 읽기 전용으로 유지되며, 설정 변경은 별도의 변경 창, 피어 리뷰 및 롤백 계획이 필요합니다. 주요 기능으로는 읽기 전용 연결 패턴, 배치 수집, TextFSM을 통한 구조적 파싱, 보호된 설정 변경 패턴을 포함합니다. 안전 기본값으로 타임아웃 설정, 자격 증명 하드코딩 금지, 명시적 연산자 플래그를 통한 설정 명령 실행 제한, save_config() 호출 분리 등을 강조합니다. 또한 인벤토리 명시, 동시성 제한, 변경 전후 증적 캡처 등의 모범 사례를 검토 체크리스트로 제공합니다. 이 스킬은 Cisco IOS 패턴, 네트워크 설정 검증, 네트워크 인터페이스 상태 스킬과 함께 사용할 수 있습니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/netmiko-ssh-automation

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Netmiko SSH 자동화은(는) 무엇을 하나요?

이 스킬은 Netmiko를 사용하여 네트워크 장치에 연결하는 Python 자동화를 작성하거나 검토할 때 사용합니다. 기본 경로는 읽기 전용으로 유지하며, 설정 변경은 별도의 변경 창, 피어 리뷰 및 롤백 계획이 필요합니다.

사용 시점

  • 라우터, 스위치 또는 방화벽에서 show 명령어 출력 수집
  • 인터페이스, 라우팅 또는 설정 증적을 위한 소규모 감사 스크립트 구축
  • 네트워크 SSH 스크립트에 타임아웃 및 예외 처리 추가
  • TextFSM 템플릿이 있는 경우 명령어 출력 파싱
  • 프로덕션 장치에 적용 전 자동화 검토

안전 기본값

  • 읽기 전용 send_command() 수집으로 시작
  • 인벤토리를 작고 명시적으로 유지, 전체 주소 범위 스캔 금지
  • 환경 변수, 볼트 또는 getpass 사용, 자격 증명 하드코딩 금지
  • 연결 및 읽기 타임아웃 설정
  • 오래된 장치에 과부하가 걸리지 않도록 동시성 제한
  • send_config_set() 전에 명시적 연산자 플래그 필요
  • 변경 사항이 검증되고 승인될 때까지 save_config() 호출 금지

읽기 전용 연결 패턴

import os
from getpass import getpass
from netmiko import ConnectHandler
from netmiko.exceptions import (
    NetmikoAuthenticationException,
    NetmikoTimeoutException,
    ReadTimeout,
)

device = {
    "device_type": "cisco_ios",
    "host": "192.0.2.10",
    "username": os.environ.get("NETMIKO_USERNAME") or input("사용자명: "),
    "password": os.environ.get("NETMIKO_PASSWORD") or getpass("비밀번호: "),
    "secret": os.environ.get("NETMIKO_ENABLE_SECRET"),
    "conn_timeout": 10,
    "auth_timeout": 20,
    "banner_timeout": 15,
    "read_timeout_override": 30,
}

try:
    with ConnectHandler(**device) as conn:
        if device.get("secret") and not conn.check_enable_mode():
            conn.enable()
        output = conn.send_command("show ip interface brief", read_timeout=30)
        print(output)
except NetmikoAuthenticationException:
    print("인증 실패")
except NetmikoTimeoutException:
    print("SSH 연결 시간 초과")
except ReadTimeout:
    print("명령어 읽기 시간 초과")

예제에서는 문서화 범위의 플레이스홀더 주소를 사용하세요. 실제 인벤토리는 무시된 로컬 파일 또는 비밀 관리 시스템에 보관하세요.

배치 수집

from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Any

def collect_show(device: dict[str, Any], command: str) -> dict[str, Any]:
    host = device["host"]
    try:
        with ConnectHandler(**device) as conn:
            output = conn.send_command(command, read_timeout=45)
        return {"host": host, "ok": True, "output": output}
    except (NetmikoAuthenticationException, NetmikoTimeoutException, ReadTimeout) as exc:
        return {"host": host, "ok": False, "error": type(exc).__name__}

results = []
with ThreadPoolExecutor(max_workers=8) as pool:
    futures = [pool.submit(collect_show, device, "show version") for device in devices]
    for future in as_completed(futures):
        results.append(future.result())

max_workers는 장치 환경과 AAA 시스템이 더 높은 연결 볼륨을 처리할 수 있다고 알려진 경우가 아니라면 낮게 유지하세요.

구조적 파싱

Netmiko는 TextFSM, TTP 또는 Genie를 통해 지원되는 명령어 출력을 파싱할 수 있습니다. 파서 출력을 최적화 도구로 취급하고 유일한 증적 경로로 간주하지 마세요.

with ConnectHandler(**device) as conn:
    parsed = conn.send_command(
        "show ip interface brief",
        use_textfsm=True,
        raise_parsing_error=False,
        read_timeout=30,
    )

if isinstance(parsed, str):
    print("파서 템플릿이 일치하지 않음, 검토를 위해 원시 출력 저장")
else:
    for row in parsed:
        print(row)

파싱이 차단 결정을 주도하는 경우, 파싱된 결과와 함께 원시 명령어 출력을 보관하여 운영자가 불일치를 검사할 수 있도록 하세요.

보호된 설정 패턴

import os

commands = [
    "interface GigabitEthernet0/1",
    "description CHANGE-1234 UPLINK-TO-CORE",
]

apply_changes = os.environ.get("APPLY_NETWORK_CHANGES") == "1"

if not apply_changes:
    print("드라이 런 모드. 후보 명령어:")
    print("\n".join(commands))
else:
    with ConnectHandler(**device) as conn:
        conn.enable()
        before = conn.send_command("show running-config interface GigabitEthernet0/1")
        output = conn.send_config_set(commands)
        after = conn.send_command("show running-config interface GigabitEthernet0/1")
        print(before)
        print(output)
        print(after)
        print("시동 구성을 저장하기 전에 동작을 확인하세요.")

구성 저장은 별도의 승인 단계입니다. 프로덕션에서는 롤백 스니펫을 포함하고 변경 기록에 변경 전후 증적을 캡처하세요.

검토 체크리스트

  • 스크립트가 명시적인 인벤토리 소스를 식별합니까?
  • 자격 증명이 소스, 로그 및 예외 메시지에 없습니까?
  • conn_timeout, auth_timeout 및 명령어 read_timeout이 설정되었습니까?
  • 전체 배치를 중단하지 않고 장치별로 실패를 보고합니까?
  • 스크립트가 광범위한 스캔과 무제한 동시성을 피합니까?
  • 설정 변경이 드라이 런 또는 명시적 연산자 플래그 뒤에 있습니까?
  • save_config()가 초기 푸시와 분리되어 검증과 연결됩니까?

안티 패턴

  • 소스에 비밀번호, enable 비밀 또는 개인 키를 하드코딩
  • 설정 명령어를 기본 코드 경로로 전송
  • 검토된 인벤토리 대신 CIDR 범위에 대해 자동화 실행
  • 전체 실행 구성을 세니타이제이션 없이 공유 시스템에 로깅
  • 파서 성공을 장치 상태가 올바르다는 증거로 취급

함께 보기

  • 스킬: cisco-ios-patterns
  • 스킬: network-config-validation
  • 스킬: network-interface-health

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

관련 스킬