ansible - How to use ansible to test network connection?
问题描述
I am setting Zabbix
agent service on many hosts, it can't confirm network is available between Zabbix server and Zabbix agent even service is up.
For example, I install Zabbix-agent on host A by ansible playbook. And there is already a Zabbix server on host B.
How can I use ansible to test, if host A can access port 10050 of host A and if host A can access port 10051
of host B?
Can you help to tell me which modules are suitable for the above network testing? In addition, how to loop inventory hosts in ansible-playbook.
Thanks.
解决方案
You can take advantage of wait_for
module to accomplish this.
Example:
- name: verify port 10050 is listening on hostA
wait_for:
host: hostA
port: 10050
delay: 5
state: started
delegate_to: hostB
To iterate through the hosts in the inventory file, you can use inventory_hostnames
module:
with_inventory_hostnames:
- all
推荐阅读
- openssl - 经过身份验证的加密和 OpenSSL 密钥
- javascript - 通过 Ajax 请求发送 OfficeJS 2D 数组
- javascript - 抓取 javascript 提交操作
- javascript - 如何将 javascript 数组转换为格式化的 JSON 字符串
- laravel - Laravel - 无法使用 .. 使用 2 个可能的身份验证器在 SMTP 服务器上进行身份验证
- android - Bundle 变空并且它没有使用 bundle args
- google-api - 下一页令牌
- java - 断言空检查
- aws-step-functions - 如何恢复暂停的 Step Function 状态机?
- xamarin.android - Xamarin.Build.Download 错误