使用 Ansible 测试服务器是否可从主机访问并打开端口 [英] Test if a server is reachable from host and has port open with Ansible

查看:24
本文介绍了使用 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 测试服务器是否可从主机访问并打开端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆