Created
March 23, 2022 08:35
-
-
Save ciiiii/6e483dcea4bb888f68e7547626b4532c to your computer and use it in GitHub Desktop.
playbook with block and rescue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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