首页 > 解决方案 > 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.

标签: ansible

解决方案


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

推荐阅读