Ansible 如何在游戏中忽略连接错误

Ansible 如何在游戏中忽略连接错误,ansible,Ansible,当无法访问某些主机时,我想继续我的剧本,以执行其他一些任务。然而,ignore_错误似乎不起作用。未打印调试消息。 ansible版本是2.5.4。在这个版本中有没有办法做到这一点 - name: check accessibility hosts: myhosts tasks: - ping: ignore_errors: yes - fail: msg: "Host {{ansible_hostname}} is not accessibl

当无法访问某些主机时,我想继续我的剧本,以执行其他一些任务。然而,ignore_错误似乎不起作用。未打印调试消息。 ansible版本是2.5.4。在这个版本中有没有办法做到这一点

- name: check accessibility
  hosts: myhosts
  tasks:
    - ping:
      ignore_errors: yes
    - fail:
        msg: "Host {{ansible_hostname}} is not accessible"
      when: False

一个选项是ping中的每个“inventory\u hostname”,如果ping失败,则结束播放

- hosts: myhosts
  gather_facts: no
  tasks:
    - block:
        - delegate_to: localhost
          command: ping -c1 "{{ inventory_hostname }}"
      rescue:
       - fail:
           msg: "{{ inventory_hostname }} not accessible. End of play."
    - debug:
        msg: "Host {{ inventory_hostname }} continue play."
    - setup:
注:

  • 设置“收集事实:否”,因为我们不确定所有主机都可用
  • 使用“目录\u主机名”,因为“收集事实:否”
  • 如有必要,在“块”之后使用“设置”模块
使用可用主机运行剧本:test_01、test_02、test_03和unavailable host test_99给出(节略):


一个选项是ping中的每个“inventory\u hostname”,如果ping失败,则结束播放

- hosts: myhosts
  gather_facts: no
  tasks:
    - block:
        - delegate_to: localhost
          command: ping -c1 "{{ inventory_hostname }}"
      rescue:
       - fail:
           msg: "{{ inventory_hostname }} not accessible. End of play."
    - debug:
        msg: "Host {{ inventory_hostname }} continue play."
    - setup:
注:

  • 设置“收集事实:否”,因为我们不确定所有主机都可用
  • 使用“目录\u主机名”,因为“收集事实:否”
  • 如有必要,在“块”之后使用“设置”模块
使用可用主机运行剧本:test_01、test_02、test_03和unavailable host test_99给出(节略):