Skip to content

Instantly share code, notes, and snippets.

@ciiiii
Created March 23, 2022 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ciiiii/6e483dcea4bb888f68e7547626b4532c to your computer and use it in GitHub Desktop.
Save ciiiii/6e483dcea4bb888f68e7547626b4532c to your computer and use it in GitHub Desktop.
playbook with block and rescue
---
- hosts: k8s-cluster
gather_facts: false
any_errors_fatal: true
tasks:
- name: try block
when: inventory_hostname not in groups['kube-master']
block:
- name: first try
command: /bin/false
register: try_result
changed_when: try_result is success
rescue:
- name: second try
command: /bin/false
register: try_result
changed_when: try_result is success
always:
- name: display error
when: try_result is failed
debug:
var: try_result.stderr_lines
# - name: Failed when twice try both failed
# command: /bin/false
# when: try_result is failed
- name: test if still running
debug:
msg: "still running"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment