Use it when configuring, checking or troubleshooting CLI Automation in Network Automation.
CLI Automation
CLI Automation drives device command-line interfaces programmatically while handling prompts, privilege modes, command ordering, parsing and platform-specific output.
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.
commands → CLI → text → parser → structured data
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 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 · 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.
- 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.
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
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
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
python3 show_int.pyExpected 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 upParse 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.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.
Quick lookup tables
CLI Automation Network Automation proof-boundary map
Fast intent/scope, management-operation, device-state and network-acceptance boundaries for CLI Automation.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Intent / scope | Source revision and exact targets are explicit | Stale inventory, hidden selector or wrong variables change scope |
| Management operation | Transport/model/payload and per-device response are traceable | Auth/capability/parser differences hide partial or wrong execution |
| Device state | Effective and persistent state are read back | Accepted config/API result is mistaken for convergence |
| Network proof | Original control/data-plane or service test passes | Automation summary substitutes for actual network acceptance |