Abort playbook in case ping task failed

21 views
Skip to first unread message

דודו דודו

unread,
Apr 6, 2020, 5:10:18 PM4/6/20
to Ansible Project
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:

 

Vladimir Botka

unread,
Apr 7, 2020, 12:24:22 AM4/7/20
to דודו דודו, ansible...@googlegroups.com
On Mon, 6 Apr 2020 14:10:18 -0700 (PDT)
דודו דודו <dudu.c...@gmail.com> wrote:

> I'm checking ping on a few of my groups. I wish to abort the playbook if
> one of the IPs is not reachable
>
> - 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

Kai Stian Olstad

unread,
Apr 10, 2020, 2:51:07 AM4/10/20
to ansible...@googlegroups.com
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


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages