How to handle host unreachable error in a playbook

12 views
Skip to first unread message

Saravanan

unread,
Feb 3, 2019, 10:10:42 PM2/3/19
to Ansible Project
Hi Ansible Experts,
We would need to check the fail-over check of remote servers in the beginning of the play and delegate them during the play execution when its reachable.

---
- name:Remote server status check
  gather_facts: no
  hosts: 127.0.0.1

  vars:
    remoteserver1: remoteserver1.com
    remoteserver2: remoteserver2.com

  tasks:
    - name: Gather facts from server1
  setup:
  delegate_to: "{{ remoteserver1 }}"
  register: status1
  any_errors_fatal: true
  
    - name: Gather facts from server2
  setup:
  delegate_to: "{{ remoteserver2 }}"
  register: status2
  any_errors_fatal: true

But the play fails as soon as any one of the remote server is not reachable. Can you please suggest the right approach to handle this error for failed servers.
Reply all
Reply to author
Forward
0 new messages