ansible - Ansible cli_command 提示未按预期工作
问题描述
我正在尝试从 Cisco 设备执行 ping 命令。我必须使用扩展的 ping 命令,我不能只在一行中指定参数。
这是路由器所期望的:
ping
Protocol [ip]:
Target IP address: <IP HERE>
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: y
Ingress ping [n]:
Source address or interface: <INT HERE>
DSCP Value [0]:
Type of service [0]:
Set DF bit in IP header? [no]:
Validate reply data? [no]:
Data pattern [0x0000ABCD]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Sweep range of sizes [n]:
如您所见,我只定义了目标 IP、扩展命令标志和源接口。
这就是我的任务现在的样子:
- name: Run Cisco command (ping)
cli_command:
command: ping
prompt:
- "Protocol [ip]:"
- "Target IP address:"
- "Repeat count [5]:"
- "Datagram size [100]:"
- "Timeout in seconds [2]:"
- "Extended commands [n]:"
- "Ingress ping [n]:"
- "Source address or interface:"
- "DSCP Value [0]:"
- "Type of service [0]:"
- "Set DF bit in IP header? [no]:"
- "Validate reply data? [no]:"
- "Data pattern [0x0000ABCD]:"
- "Loose, Strict, Record, Timestamp, Verbose[none]:"
- "Sweep range of sizes [n]:"
answer:
- ''
- "{{ item }}"
- "{{ count }}" (I'm specifying the number of packets here but its optional, same for the size)
- "{{ size }}"
- ''
- y
- ''
- loopback1
- ''
- ''
- ''
- ''
- ''
- ''
- ''
with_lines: cat "{{ dest_file }}"
ignore_errors: yes
when: ansible_network_os == 'ios'
这就是 ansible 返回的内容:
"results":[
{
"ansible_loop_var":"item",
"item": first target here,
"changed":false,
"failed":true,
"invocation":{
"module_args":{
"sendonly":false,
"prompt":[
"Protocol [ip]",
"Target IP address",
"Repeat count [5]",
"Datagram size [100]:",
"Timeout in seconds [2]:",
"Extended commands [n]",
"Ingress ping [n]",
"Source address or interface",
"DSCP Value [0]",
"Type of service [0]",
"Set DF bit in IP header? [no]",
"Validate reply data? [no]",
"Data pattern [0x0000ABCD]",
"Loose, Strict, Record, Timestamp, Verbose[none]",
"Sweep range of sizes [n]"
],
"check_all":true,
"newline":true,
"command":"ping",
"answer":[
"",
"192.168.1.1", (first target here)
"5",
"72",
"",
"y",
"",
"loopback 1",
"",
"",
"",
"",
"",
"",
""
]
}
},
"ansible_facts":{
"discovered_interpreter_python":"/usr/bin/python"
},
**"msg":"timeout value 30 seconds reached while trying to send command: ping"**
},
{
"ansible_loop_var":"item",
**"stdout":"% Unknown protocol - \"ping\", type \"ping ?\" for help",**
"failed":false,
"changed":false,
"item":"second target here",
"invocation":{
"module_args":{
"sendonly":false,
"prompt":[
"Protocol [ip]",
"Target IP address",
"Repeat count [5]",
"Datagram size [100]:",
"Timeout in seconds [2]:",
"Extended commands [n]",
"Ingress ping [n]",
"Source address or interface",
"DSCP Value [0]",
"Type of service [0]",
"Set DF bit in IP header? [no]",
"Validate reply data? [no]",
"Data pattern [0x0000ABCD]",
"Loose, Strict, Record, Timestamp, Verbose[none]",
"Sweep range of sizes [n]"
],
"check_all":true,
"newline":true,
"command":"ping",
"answer":[
"",
"192.168.1.2", (second target here)
"5",
"72",
"",
"y",
"",
"loopback 1",
"",
"",
"",
"",
"",
"",
""
]
}
},
"stdout_lines":[
**"% Unknown protocol - \"ping\", type \"ping ?\" for help"**
]
}
首先,每对 IP 中的第一个总是超时,即使它可以访问。不管是 30 秒还是 120 秒超时。
二、为什么第一个提示(协议)取值“ping”而不是值“”?"% 未知协议 - "ping",键入 "ping ?" 寻求帮助"
我将空答案更改为: "", '', \n, "ip" 但没有任何效果,结果始终相同。
我还将提示更改为:“协议 [ip]:”、“协议 [ip]”、“协议 [ip]:”、协议 [ip]、协议 [ip],但没有一个有效。
这个想法是 15 个答案按顺序回答 15 个提示。
知道我做错了什么吗?
解决方案
推荐阅读
- python - 'my_app' 模块未找到错误 Django - 执行使用 my_app 模型的脚本
- geolocation - 在一次 Mediawiki API 调用中检索项目、其浏览量和地理属性
- android - 为什么我在导入领域数据库时无法在 android studio 上运行我的项目?
- django - 在 Django Rest Framework 中访问 .data 后更新序列化程序中的值
- android - Firestore 查询列表映射对象
- python - 如何将大小为 3 的元组列表制作成键值对?
- python - 魔术 8 球比赛的测试用例
- json - 如何在 swift 4 中使用 Graphql 获取 json 值数组?
- java - 实体类中的所有实例变量是否都在数据库中持久化?
- android - 如何在反应原生 ios 设备中读取通话记录或通话记录?