You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Real-world automation must handle failures gracefully. Ansible provides several mechanisms for error handling, custom failure conditions, and debugging tools to help you troubleshoot issues.
By default, when a task fails on a host:
any_errors_fatal: true is set)Continue execution even when a task fails:
tasks:
- name: Check if legacy app exists
command: which legacy-app
register: legacy_check
ignore_errors: true
- name: Report legacy app status
debug:
msg: "Legacy app {{ 'found' if legacy_check.rc == 0 else 'not found' }}"
Warning: Use
ignore_errorssparingly --- it suppresses all errors, which can mask real problems. Preferfailed_whenfor fine-grained control.
Continue when a host is unreachable (network issues, SSH failures):
tasks:
- name: Attempt to gather info
command: hostname
ignore_unreachable: true
- name: This still runs even if host was unreachable
debug:
msg: "Continuing..."
Define custom failure conditions:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.