本文介绍了使用 Ansible 测试服务器是否可从主机访问并打开端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想测试我配置的主机是否可以访问特定服务器并连接到特定 TCP 端口.如果它不能,剧本应该会失败.
I want to test if the host I am provisioning can reach a specific server and connect to a specific TCP port. If it can't the playbook should fail.
我该怎么做?
推荐答案
有 wait_for 模块.
要检查 target.host
是否可以访问 remote.host:8080
:
There is wait_for module for this.
To check that target.host
can access remote.host:8080
:
- hosts: target.host
tasks:
- wait_for: host=remote.host port=8080 timeout=1
- debug: msg=ok
文档中还有很多其他示例.
There are a lot of other examples in the documentation.
这篇关于使用 Ansible 测试服务器是否可从主机访问并打开端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!