如何解决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,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,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,"item":"second target here","192.168.1.2",(second target here)
"5","stdout_lines":[
**"% Unknown protocol - \"ping\",type \"ping ?\" for help"**
]
}
首先,每对 IP 中的第一个总是超时,即使它可以访问。无论是 30 秒还是 120 秒超时都没有关系。
第二,为什么第一个提示(协议)取值“ping”而不是值“”? "% 未知协议 - "ping",键入 "ping ?" 寻求帮助"
我将空答案更改为:"",'',\n,"ip" 但没有任何效果,结果始终相同。
我也将提示更改为:“Protocol [ip]:”、“Protocol [ip]”、“Protocol [ip]:”、Protocol [ip]、Protocol [ip] 但都没有工作。
这个想法是 15 个答案按顺序回答 15 个提示。
知道我做错了什么吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。