Difference between revisions of "Run play only if host is reachable"

From MyWiki
Jump to: navigation, search
(Created page with "Create a new group of the reachable hosts: <source lang="yaml"> - name: check reachable hosts hosts: all gather_facts: no tasks: - command: ping -c1 {{ inventory_hos...")
(No difference)

Revision as of 17:39, 8 October 2019

Create a new group of the reachable hosts:

- name: check reachable hosts
  hosts: all
  gather_facts: no
  tasks:
    - command: ping -c1 {{ inventory_hostname }}
      delegate_to: localhost
      register: ping_result
      ignore_errors: yes
    - group_by: key=reachable
      when: ping_result|success