ansible-playbook 被管理主机网络测试


  • name: Test connectivity to 61.139.2.69:80 from managed hosts
    hosts: all # 测试被管理主机的连通性
    gather_facts: no # 不需要收集主机信息以加快执行速度
    tasks:
    • name: Wait for port 80 on 61.139.2.69 to become reachable
      wait_for:
      host: 61.139.2.69
      port: 80
      timeout: 10 # 超时时间为10秒
      ignore_errors: yes
      register: port_status
    • name: Report connectivity status
      debug:
      msg: >
      {{ ‘Connectivity to 61.139.2.69:80 is reachable’ if port_status.state == ‘started’
      else ‘Connectivity to 61.139.2.69:80 is not reachable’ }}