Red Hat Certified Engineer RHCE · Free Practice Question Medium
Question 6
You are tasked with ensuring a playbook continues to run even if a specific task fails. How would you configure error handling in the playbook using the ignore_errors directive to bypass task failures?
-
A
Using
ignore_errorsto Continue Playbook Execution
To bypass task failures and continue:- - hosts: all
- tasks:
- - name: Task that might fail
- ansible.builtin.shell: "command_that_might_fail"
- ignore_errors: yes
This ensures that the playbook continues running even if the task fails.
-
B
This is a performance based question and not multiple choice. Therefore the answer is in #1. If you require additional explanation, please ask your question in the Q&A section.
Reveal correct answer
Correct answer: A
A.
This playbook demonstrates how to use the ignore_errors directive in Ansible to ensure the playbook continues execution even if a specific task fails. By setting ignore_errors: yes for a task, any error occurring during the execution of that task will be bypassed, and subsequent tasks will proceed as intended. This method is particularly useful in scenarios where the failure of certain tasks is non-critical or expected, allowing the rest of the automation to continue uninterrupted.
Line-by-Line Explanation:
Define the Target Hosts:
- - hosts: all
Specifies that the playbook will be executed on all hosts listed in the inventory.
Define the Task That Might Fail:
- - name: Task that might fail
- ansible.builtin.shell: "command_that_might_fail"
- ignore_errors: yes
Executes a shell command (
command_that_might_fail) that has a potential to fail.The
ignore_errors: yesdirective ensures that any failure in this task does not halt the playbook execution. Instead, the playbook moves on to the next tasks.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
