Testing Ansible wait_for not response correct错误

Testing Ansible wait_for not response correct错误,testing,ansible,connectivity,Testing,Ansible,Connectivity,我试图测试一批连接,但所有错误响应失败的连接都是“超时”,但我知道(我测试过)其中一些连接是“没有到主机的路由”。 我怎样才能在等待中做到这一点 - name: Test connectivity flow wait_for: host: "{{ item.destination_ip }}" port: "{{ item.destination_port }}" state: started # Port should be open de

我试图测试一批连接,但所有错误响应失败的连接都是“超时”,但我知道(我测试过)其中一些连接是“没有到主机的路由”。 我怎样才能在等待中做到这一点

- name: Test connectivity flow
  wait_for: 
    host: "{{ item.destination_ip }}"
    port: "{{ item.destination_port }}"
    state: started         # Port should be open
    delay: 0               # No wait before first check (sec)
    timeout: 3             # Stop checking after timeout (sec)
  delegate_to: "{{ item.source_ip }}"
  failed_when: false
  register: test_connectivity_flow_result

- name: Append result message to result list msg
  set_fact:
    result_list_msg: "{% if test_connectivity_flow_result.msg is defined %}{{ result_list_msg + [test_connectivity_flow_result.msg] }}{% else %}{{ result_list_msg + [ '' ] }}{% endif %}"
当前响应:等待1.1.1.1:1040时超时


预期响应:没有到主机1.1.1.1:1040的路线,请引用

等待–在继续之前等待条件

如果我“重新表述”您所写的条件,这将给出类似的内容:“等待主机X成为可解析的目的地,等待端口22在该目的地打开,在3s后立即重试并超时”

这通常可能是您启动的测试,因为您启动了一个新vm并在dns中注册了它。因此,您需要等待dns传播和ssh端口可用

在您的情况下,您会得到一个超时,因为您的主机名永远不会成为可解析的地址

如果您特别想测试没有到主机的路由,并且不想等到路由最终变为可用,那么您需要以另一种方式进行测试。下面是一个带有
ping
模块的简单示例剧本:

---
- name: Very basic connection test 
  hosts: localhost
  gather_facts: false

  tasks:

    - name: Test if host is reachable (will report no route if so)
      ping:
      delegate_to: nonexistent.host.local
其结果是:

PLAY [Very basic connection test] *****************************************************

TASK [Test if host is reachable (will report no route if so)] *************************
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname nonexistent.host.local: Name or service not known", "unreachable": true}

PLAY RECAP ****************************************************************************
localhost                  : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0
请注意:

  • 将报告没有到主机的路由(如果有)
  • 将隐式尝试连接到端口22
  • 将确保主机已安装python并准备好通过ansible进行管理

如果您尝试检查的主机不应满足上述所有条件(例如,即使未安装python,您也希望测试成功),则需要其他场景。通过
命令
模块运行ICMP
ping
是多种解决方案之一。

引用

等待–在继续之前等待条件

如果我“重新表述”您所写的条件,这将给出类似的内容:“等待主机X成为可解析的目的地,等待端口22在该目的地打开,在3s后立即重试并超时”

这通常可能是您启动的测试,因为您启动了一个新vm并在dns中注册了它。因此,您需要等待dns传播和ssh端口可用

在您的情况下,您会得到一个超时,因为您的主机名永远不会成为可解析的地址

如果您特别想测试没有到主机的路由,并且不想等到路由最终变为可用,那么您需要以另一种方式进行测试。下面是一个带有
ping
模块的简单示例剧本:

---
- name: Very basic connection test 
  hosts: localhost
  gather_facts: false

  tasks:

    - name: Test if host is reachable (will report no route if so)
      ping:
      delegate_to: nonexistent.host.local
其结果是:

PLAY [Very basic connection test] *****************************************************

TASK [Test if host is reachable (will report no route if so)] *************************
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname nonexistent.host.local: Name or service not known", "unreachable": true}

PLAY RECAP ****************************************************************************
localhost                  : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0
请注意:

  • 将报告没有到主机的路由(如果有)
  • 将隐式尝试连接到端口22
  • 将确保主机已安装python并准备好通过ansible进行管理

如果您尝试检查的主机不应满足上述所有条件(例如,即使未安装python,您也希望测试成功),则需要其他场景。通过
命令
模块运行ICMP
ping
是多种解决方案之一。

但我想测试不同的端口,其中一些端口将超时,其他端口将无法路由到主机。然后首先测试路由,然后测试有路由的主机上的端口。我怎么做?但我想测试不同的端口,其中一些端口将超时,其他端口将没有到主机的路由。然后首先测试路由,然后测试有路由的主机上的端口。我怎么做?