Use this when automating Cisco devices via SSH and CLI.
SSH / CLI
SSH/CLI automation sends normal CLI commands over SSH with libraries like Netmiko, Paramiko or Scrapli and parses the text output, working on almost any device but sensitive to prompts and output formats.
1. SSH/CLI automation on Cisco.
2. network_cli connection with become for enable.
3. Parse with Genie/TextFSM.
4. ios_config with backup and diff.
5. Handle prompts.
SSH → exec/enable → commands
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
Record device ID/management endpoint, platform/version, YANG model/revision or CLI operation, request/run ID; inspect the runtime/control-plane result; then query the selected Cisco device configuration/operational state and forwarding behavior where relevant through an independent read path and compare it with the versioned intent. For Cisco Automation → SSH / CLI, the evidence must connect the control-plane result to the selected Cisco device configuration/operational state and forwarding behavior where relevant and explain any gap between desired, controller-reported and consumer-visible state.
Step 2 Common mistakes Narrow the fault
- Screen-scraping without structured parsing.
- Forgetting
terminal length 0.
Step 3 Where it fails Narrow the fault
Failure analysis for Cisco Automation → SSH / CLI should follow the path through the components: inventory/controller → transport/API/CLI → device parser/YANG datastore → control-plane state → forwarding/operational read-back. Common failure classes include platform syntax/model drift, privilege/auth mismatch, partial config, parser success without feature activation, asynchronous convergence and controller cache differing from device state. Before retrying a mutating operation, read current target state using the stable identity device ID/management endpoint, platform/version, YANG model/revision or CLI operation, request/run ID; if state is unknown, stop broad retries.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Works on almost any device.
- Parsing text is fragile.
- Handle prompts and timeouts.
ansible <dev> -m cisco.ios.ios_command -a "commands='show run | i hostname'"— CLI via Ansiblepython3 -c 'import netmiko'— Netmiko- privilege level 15 or enable via become — access
ReferenceWhy it matters1 section · depth on demand
In depth
SSH/CLI automation on Cisco devices sends the same commands an engineer would type, through libraries that handle login, prompts and paging. It works on every IOS, IOS XE, NX-OS and IOS XR device, which makes it the universal fallback when no API is available.
| Library | Strength |
|---|---|
| Netmiko | Simple, many platforms |
| Scrapli | Fast, async support |
Ansible network_cli | Playbook-based, resource modules |
| Unicon (pyATS) | Rich device state handling |
from scrapli.driver.core import IOSXEDriver
with IOSXEDriver(host="sw01", auth_username=u, auth_password=p, auth_strict_key=True) as c:
print(c.send_command("show version").genie_parse_output()["version"]["version"])
Parse output into structured data immediately; scraping text with ad-hoc regexes breaks when output formats change.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
Cisco Automation → SSH / CLI is owned at runtime by the automation client/controller communicating with Cisco devices through supported APIs, YANG models or CLI. Its durable intent is versioned automation with device inventory, platform/model capability expectations and bounded configuration intent; the stable identity contract is device ID/management endpoint, platform/version, YANG model/revision or CLI operation, request/run ID. The consumer-visible target is the selected Cisco device configuration/operational state and forwarding behavior where relevant. The operating invariants are that device/platform capability is known, configuration scope is explicit, parser/model assumptions match software version, write success is followed by read-back and control/data-plane verification remains separate. Follow the chain of components inventory/controller → transport/API/CLI → device parser/YANG datastore → control-plane state → forwarding/operational read-back and record which layer currently owns truth. The linked authority for bounded mechanics is Cisco DevNet — YANG Suite Documentation; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Cisco Automation > SSH / CLI. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://developer.cisco.com/docs/yangsuite/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
Capture at minimum device, platform/version, request/command/RPC ID, model/path, config diff, error, operational state and forwarding/consumer verification.