Abort playbook in case ping task failed

HI

I’m checking ping on a few of my groups. I wish to abort the playbook if one of the IPs is not reachable - How should I update the playbook

Thanks

Playbook

  • hosts:
  • postgres1
  • kafka
  • repository

become: true
gather_facts: False
tasks:

  • name: Verify that all hosts are reachable
    ping:

Try this

- hosts:
    - postgres1
    - kafka
    - repository
  become: true
  gather_facts: False
  tasks:
    - block:
        - wait_for_connection:
            timeout: 5
      rescue:
        - debug:
            msg: "{{ inventory_hostname }} not available. End play."
        - meta: end_play
    - debug:
        msg: All hosts available. Continue play.
    - setup:

HTH,

  -vlado

Or just set "any_errors_fatal: true" on the play.
https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#aborting-the-play