Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue Example #27

Closed
ondrejsika opened this issue Sep 14, 2022 · 1 comment
Closed

Rescue Example #27

ondrejsika opened this issue Sep 14, 2022 · 1 comment

Comments

@ondrejsika
Copy link
Owner

https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html#id4

---
- name: Rescue Example
  hosts: all
  gather_facts: false

  tasks:
  - name: Handle the error
    block:
      - name: Print a message
        ansible.builtin.debug:
          msg: 'I execute normally'

      - name: Force a failure
        ansible.builtin.command: /bin/false

      - name: Never print this
        ansible.builtin.debug:
          msg: 'I never execute, due to the above task failing, :-('

    rescue:
      - name: Print when errors
        ansible.builtin.debug:
          msg: 'I caught an error, can do stuff here to fix it, :-)'

    always:
      - name: Always do this
        ansible.builtin.debug:
          msg: "This always executes, :-)"

@ondrejsika
Copy link
Owner Author

already done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant