命令选型与 CLI
命令选型指南
Section titled “命令选型指南”| 需求 | 推荐命令 | 说明 |
|---|---|---|
| 立刻执行一条命令 | rauto exec | 最适合临时排障和快速验证 |
| 渲染已保存模板并执行 | rauto template | 适合把命令逻辑做成可复用模板 |
| 驱动交互式 prompt/response | rauto flow | 适合向导式 CLI 操作 |
| 通过 SFTP 上传本地文件 | rauto upload | 要求目标主机支持 sftp 子系统 |
| 执行一个带回滚的事务块 | rauto tx | 适合单目标、单事务单元 |
| 按 JSON 执行事务工作流 | rauto tx-workflow | 适合拆成多个 block 的变更流程 |
| 执行多设备计划 | rauto orchestrate | 适合多台设备串行/并发编排 |
| 打开本地控制台 | rauto web | 适合自管理和可视化执行 |
| 作为托管执行节点启动 | rauto agent | 适合接入 rauto-manager |
公共连接参数
Section titled “公共连接参数”大多数执行类命令都会复用同一组全局连接参数:
| 参数 | 说明 |
|---|---|
--host | 设备主机名或 IP |
--username | SSH 用户名 |
--password | SSH 密码 |
--enable-password | 特权模式密码 |
--ssh-port | SSH 端口 |
--ssh-security | SSH 兼容档位:secure、balanced、legacy-compatible |
--linux-shell-flavor | Linux shell 退出码解析方式:posix 或 fish |
--device-profile | 目标设备 profile,默认是 linux |
--connection | 直接引用已保存连接配置 |
--save-connection | 成功连接后保存当前有效配置 |
--save-password | 与 --save-connection 搭配,保存密码字段 |
最常用的命令示例
Section titled “最常用的命令示例”rauto exec "show ip int br" \ --host 192.168.1.1 \ --username admin \ --password secret \ --device-profile cisco如果需要在指定模式执行:
rauto exec "show bgp neighbor" --connection core-sw-01 --mode Enabletemplate
Section titled “template”rauto template configure_vlan.j2 \ --vars ./vars.json \ --connection core-sw-01只看渲染结果,不实际执行:
rauto template configure_vlan.j2 --vars ./vars.json --dry-runrauto flow \ --template cisco_like_copy \ --vars-json '{"command":"copy scp: flash:/new.bin","server_addr":"192.168.1.50","remote_path":"/images/new.bin","transfer_username":"backup","transfer_password":"secret"}' \ --connection core-01upload
Section titled “upload”rauto upload \ --local-path ./daemon.conf \ --remote-path /tmp/daemon.conf \ --connection linux-jump-01执行类命令普遍支持录制:
rauto exec "show version" \ --connection core-sw-01 \ --record-file ./recording.jsonl \ --record-level key-events-only回放时可以先列出录制事件:
rauto replay ./recording.jsonl --list也可以回放某条命令:
rauto replay ./recording.jsonl --command "show version" --mode Enable连接配置的推荐做法
Section titled “连接配置的推荐做法”临时命令阶段
Section titled “临时命令阶段”先直接传 --host、--username、--password 即可。
进入重复执行阶段
Section titled “进入重复执行阶段”改用已保存连接:
rauto connection add edge-01 \ --host 192.168.1.11 \ --username admin \ --device-profile huawei之后统一使用:
rauto exec "display version" --connection edge-01进入多设备阶段
Section titled “进入多设备阶段”配合 inventory group、tx-workflow 和 orchestrate 使用,会比纯手写连接参数更稳定。
完整的管理命令族
Section titled “完整的管理命令族”当前 CLI 源码定义的管理面要比前面的快速选型表更大。
rauto device
Section titled “rauto device”根据当前源码,支持:
listshow <name>delete-custom <name>copy-builtin <source> <name> [--overwrite]diagnose <name> [--json]
rauto connection
Section titled “rauto connection”根据当前源码,支持:
testlistshow <name>delete <name>add <name>import <file> [--json]
rauto inventory
Section titled “rauto inventory”当前 inventory 操作包括:
group list [--json]group show <name> [--json]group upsert <name> [--file <path> | --content <json>]group delete <name>resolve-vars [--host <saved-connection>] [--group <name>] [--vars-file <path>] [--vars-json <json>] [--json]
rauto history
Section titled “rauto history”当前支持:
list <connection-name> [--limit <n>] [--json]show <connection-name> <id> [--json]delete <connection-name> <id>
rauto blacklist
Section titled “rauto blacklist”当前支持:
listadd <pattern>delete <pattern>check <command>
rauto templates
Section titled “rauto templates”当前支持:
listshow <name>create <name> [--file <path> | --content <template>]update <name> [--file <path> | --content <template>]delete <name>
rauto flow-template
Section titled “rauto flow-template”当前支持:
listshow <name>create <name> [--file <path> | --content <toml>]update <name> [--file <path> | --content <toml>]delete <name>
rauto backup
Section titled “rauto backup”当前支持:
create [--output <archive>]restore <archive> [--replace]list
你可能还会用到的管理命令
Section titled “你可能还会用到的管理命令”rauto device listrauto device show <name>rauto templates listrauto flow-template listrauto connection listrauto history list <connection-name>rauto blacklist listrauto backup list
录制与回放细节
Section titled “录制与回放细节”从当前源码和 README 来看,录制并不是附带能力,而是第一等能力。
当前录制 / 回放相关参数包括:
exec/template/flow/upload/tx/tx-workflow --record-file <path>exec/template/flow/upload/tx/tx-workflow --record-level <key-events-only|full>replay <record_file> --listreplay <record_file> --command <cmd> [--mode <mode>]
当前 README 还指出:
- Linux shell 场景下,回放的
SessionEvent::CommandOutput可能包含exit_code key-events-only是最小审计级别full会包含更丰富的 prompt 与状态切换细节
企业级使用建议
Section titled “企业级使用建议”把 CLI 当成命令族,而不是单条命令
Section titled “把 CLI 当成命令族,而不是单条命令”在企业使用中,更适合把 rauto 理解成一整套命令族,而不是只会跑一条 exec。
典型运维路径通常是:
- 先用
connection add规范目标 - 用
device show或device diagnose验证 profile 行为 - 用
template或flow执行可复用逻辑 - 用
tx/tx-workflow/orchestrate做受控变更下发 - 用
history、replay和备份做审计与恢复
如果你已经明确要做模板化执行,下一步请看 模板与命令流。