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...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Create a new group of the reachable hosts:
+
Create a new group of the reachable hosts:   didnt work
 
<source lang="yaml">
 
<source lang="yaml">
 
- name: check reachable hosts
 
- name: check reachable hosts
Line 11: Line 11:
 
     - group_by: key=reachable
 
     - group_by: key=reachable
 
       when: ping_result|success
 
       when: ping_result|success
 +
</source>
 +
The play that should be run only on reachable hosts:    ( didn't get this to work )
 +
<source lang="yaml">
 +
- name: your actual play
 +
  hosts: reachable
 +
  gather_facts: yes
 +
  tasks:
 +
    - debug: msg="this is {{ ansible_hostname }}"
 
</source>
 
</source>

Latest revision as of 08:34, 9 October 2019

Create a new group of the reachable hosts: didnt work

- 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

The play that should be run only on reachable hosts: ( didn't get this to work )

- name: your actual play
  hosts: reachable
  gather_facts: yes
  tasks:
    - debug: msg="this is {{ ansible_hostname }}"