ping和traceroute命令未在ansible中显示输出
我在我的剧本中添加了这个来测试traceroute,但任务并没有停止,它并没有显示输出。当我们使用ping和traceroute时,如何在一定时间后停止并显示输出ping和traceroute命令未在ansible中显示输出,ansible,ping,traceroute,Ansible,Ping,Traceroute,我在我的剧本中添加了这个来测试traceroute,但任务并没有停止,它并没有显示输出。当我们使用ping和traceroute时,如何在一定时间后停止并显示输出 我已经使用了async和poll,但是相同的问题在默认情况下是不会结束的,除非您按住CTRL^C键 但是,您可以使用参数-c运行它,以获得发送到服务器的ping计数: - name: traceroute shell: traceroute {{ my_ip }} register: result - d
我已经使用了async和poll,但是相同的问题在默认情况下是不会结束的,除非您按住CTRL^C键 但是,您可以使用参数
-c
运行它,以获得发送到服务器的ping计数:
- name: traceroute
shell: traceroute {{ my_ip }}
register: result
- debug: msg="{{ result.stdout_lines }}"
另见:
同样的情况也适用于traceroute
,它将在每次默认情况下尝试30跳。它将结束,但经过相当长的一段时间。
尝试使用选项
-m
来限制此操作
$ ping -c5 google.com
PING google.com (216.58.201.238) 56(84) bytes of data.
64 bytes from google.com (216.58.201.238): icmp_seq=1 ttl=50 time=14.8 ms
64 bytes from google.com (216.58.201.238): icmp_seq=2 ttl=50 time=14.8 ms
64 bytes from google.com (216.58.201.238): icmp_seq=3 ttl=50 time=14.3 ms
64 bytes from google.com (216.58.201.238): icmp_seq=4 ttl=50 time=14.7 ms
64 bytes from google.com (216.58.201.238): icmp_seq=5 ttl=50 time=15.3 ms
--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4020ms
rtt min/avg/max/mdev = 14.329/14.826/15.373/0.357 ms
另请参见:如前所述,您需要限制数据包的数量,您可以尝试以下两项任务:
$ traceroute -m5 google.com
traceroute to google.com (216.58.201.238), 5 hops max, 60 byte packets
1 x.x.x.x (x.x.x.x) 0.452 ms 0.427 ms 0.145 ms
2 x.x.x.x (x.x.x.x) 1.169 ms 0.873 ms 1.641 ms
3 * * *
4 * * *
5 * * *
请记住,“my_ip”变量来自不同的文件。
完成这些任务后,我得到以下输出:
- name: Execute ping
shell: "ping -c 4 {{ my_ip }}"
register: result
- name: Show result
debug:
msg: "{{ result['stdout_lines'] }}"
希望有帮助 你能给我们看看你的剧本的输出吗?非常感谢让我试试这个我会更新如果它对我有效或无效
"msg": [
"PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.",
"64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=3.86 ms",
"64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=3.35 ms",
"64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=3.22 ms",
"64 bytes from 8.8.8.8: icmp_seq=4 ttl=54 time=3.54 ms",
"",
"--- 8.8.8.8 ping statistics ---",
"4 packets transmitted, 4 received, 0% packet loss, time 3005ms",
"rtt min/avg/max/mdev = 3.224/3.494/3.860/0.246 ms"
]