Skip to content

Instantly share code, notes, and snippets.

@myh-st
Forked from evrardjp/who-is-in-play.yml
Created March 15, 2021 02:38
Show Gist options
  • Save myh-st/80e08292ecafa6fb2f0f76bc239966a8 to your computer and use it in GitHub Desktop.
Save myh-st/80e08292ecafa6fb2f0f76bc239966a8 to your computer and use it in GitHub Desktop.
block/rescue removes host from ansible_play_hosts when block fails, even when rescued!
---
- hosts: all
connection: local
gather_facts: no
tasks:
- debug:
var: ansible_play_hosts
- block:
- fail:
msg: "Failure"
when:
- "inventory_hostname == 'localhost'"
rescue:
- debug:
msg: "Success"
always:
- debug:
var: ansible_play_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment