EX294 Implement advanced Ansible automation Practice Question
An Ansible playbook is designed to run on a group of database servers. The administrator wants to ensure that a task runs only on the primary database server, which is defined in the inventory with a variable 'primary: true'. Which conditional should be used?
⚠ Common exam trap
Candidates often confuse `run_once: true` with a conditional that selects a specific host, not realizing `run_once` merely limits execution to a single arbitrary host in the group, not the one defined by a variable like `primary: true`.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
when: primary
The `when` conditional in Ansible evaluates a Jinja2 expression to determine whether a task should execute. By using `when: primary`, the task will run only on hosts where the inventory variable `primary` is defined and evaluates to `true` (a truthy value). This directly meets the requirement to target the primary database server.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
ignore_errors: yes
Why it's wrong here
ignore_errors does not affect whether the task runs.
- ✓
when: primary
Why this is correct
The when clause evaluates to true if the variable is truthy.
- ✗
run_once: true
Why it's wrong here
run_once runs the task on only one host, but not necessarily the primary.
- ✗
delegate_to: "{{ primary }}"
Why it's wrong here
Delegate_to changes the host that executes the task, but does not conditionally run it.
Go deeper
Related to this question
About these practice questions
One of 520 original EX294 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This EX294 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX294 exam.