Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

CLI Automation

Direct answer

CLI Automation drives device command-line interfaces programmatically while handling prompts, privilege modes, command ordering, parsing and platform-specific output.

When to use this

Use it when configuring, checking or troubleshooting CLI Automation in Network Automation.

First 30 seconds

1. CLI automation sends commands and parses text.

2. Use parsers for structure.

3. Config changes via config modules with diff/backup.

4. Fragile across versions — test.

5. Prefer APIs when available.

Operational verification

commands → CLI → text → parser → structured data

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Vendor-neutral network automation semantics; deep protocol behavior, platform syntax and source-system implementation remain in their owning branches
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformVendor-neutral network automation semantics; deep protocol behavior, platform syntax and source-system implementation remain in their owning branches · CLI Automation owns programmatic CLI interaction. Cisco/device-specific syntax belongs in platform branches; parsing frameworks and network protocol behavior retain their own ownership.
Scope / prerequisiteUse it when configuring, checking or troubleshooting CLI Automation in Network Automation.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

target/platform → CLI session → privilege/mode → command sequence → raw output/error → parser interpretation → config/state read-back → network acceptance

Healthy evidence: platform/mode are correct, raw output is preserved, parser matches expected format and post-change state plus network behavior verify the intent.

Step 2 Failure modes and next checks Narrow the fault

Suspicious evidence: prompt heuristics, stale TextFSM/regex templates, hidden pagination or silent command rejection produce misleading success.

Step 3 Common mistakes Narrow the fault
  • Fragile screen-scraping.
Evidence references

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.

observation · 1
Key points
  • Prompt returned ≠ command succeeded.
  • No obvious error string ≠ device accepted the intended semantics.
  • Parsed field exists ≠ parser matched the correct platform/version output.
  • Configuration mode exit ≠ configuration saved or effective.
Key checks
  • ansible <dev> -m cisco.ios.ios_command -a "commands='show ip int brief'" — run command
  • Parsers (TextFSM/Genie/ttp) — structured output
  • Config mode via *_config modules with diff — changes
ReferenceWhat it is1 section · depth on demand

Core model

Treat prompt/state detection, mode transitions, command generation, response parsing, error recognition and post-change verification as explicit boundaries rather than assuming human-style CLI interaction is deterministic.

ReferenceWhy it matters1 section · depth on demand

In depth

CLI automation drives network devices through their command line over SSH, sending commands and parsing text output. It works on almost every device, including old ones without APIs, which makes it the most widely used — and most fragile — form of network automation.

from netmiko import ConnectHandler
dev = {"device_type": "cisco_ios", "host": "10.20.0.7", "username": u, "password": p}
with ConnectHandler(**dev) as c:
    vlans = c.send_command("show vlan brief", use_textfsm=True)   # parsed into dicts
    out = c.send_config_set(["vlan 30", "name VOICE"])
    c.save_config()

Make it robust: use parsers (TextFSM/ntc-templates, Genie, TTP) instead of regex, handle prompts and timeouts explicitly, verify after changing, and prefer NETCONF/RESTCONF/APIs where the platform supports them.

ReferenceImportant terms & boundaries1 section · depth on demand

What this shows and what it does not

CLI automation shows commands were sent and responses observed; it does not by itself show the parser was correct or the network outcome converged.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

Python / Netmiko Netmiko 4.xRun show commands over SSH with explicit timeouts.

Assumptions: Credentials come from environment variables; device is reachable on SSH.

import os
from netmiko import ConnectHandler

dev = {
    "device_type": "cisco_ios",
    "host": "10.99.0.11",
    "username": os.environ["NET_USER"],
    "password": os.environ["NET_PASS"],
    "conn_timeout": 10,
}
with ConnectHandler(**dev) as conn:
    print(conn.send_command("show ip interface brief", read_timeout=30))

Expected output

Python / Netmiko Netmiko 4.xpython3 show_int.py

Expected state: The script prints the device's interface table and exits 0.

Interface              IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0     10.99.0.11      YES NVRAM  up                    up
GigabitEthernet0/1     192.0.2.1       YES NVRAM  up                    up
Loopback0              10.255.0.1      YES NVRAM  up                    up
Parse structured output (use_textfsm=True or the device's JSON/YANG interface) rather than screen-scraping text when you act on results. Illustrative authored output: field layout matches the tool, values will differ in your environment.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
cli automationnetwork cli automationautomated cliscreen scraping network
Embedded reference data

Quick lookup tables

CLI Automation Network Automation proof-boundary map

Fast intent/scope, management-operation, device-state and network-acceptance boundaries for CLI Automation.

BoundaryHealthy evidenceSuspicious evidence
Intent / scopeSource revision and exact targets are explicitStale inventory, hidden selector or wrong variables change scope
Management operationTransport/model/payload and per-device response are traceableAuth/capability/parser differences hide partial or wrong execution
Device stateEffective and persistent state are read backAccepted config/API result is mistaken for convergence
Network proofOriginal control/data-plane or service test passesAutomation summary substitutes for actual network acceptance
Confirmation

Confirm action

Continue?