Courseiva

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 merely lets the playbook continue after a task fails; it does not limit execution to any host. It is tempting because it appears to control task behaviour, and would be right when a failing task should not halt the play, but restricting execution to the primary server requires a when conditional.

  • ✓

    when: primary

    Why this is correct

    Using `when: primary` evaluates the host variable directly as a boolean condition, so the task executes only where the inventory sets `primary: true`. This satisfies the stem's constraint of restricting execution to the primary database server, since Ansible treats the variable's truthiness as the conditional test without requiring an explicit comparison.

  • ✗

    run_once: true

    Why it's wrong here

    run_once executes the task on a single host per batch regardless of which host is primary, so it may run on a replica. It is tempting because it limits execution to one host, and would suit tasks like database initialisation, but selecting the host holding 'primary: true' needs a when conditional.

  • ✗

    delegate_to: "{{ primary }}"

    Why it's wrong here

    delegate_to redirects where a task executes but does not restrict which hosts run it, so every database server still evaluates the task. It is tempting because it targets a named host, and would be correct for running a task on another managed node, but it cannot filter inventory hosts by the 'primary' variable.

About these practice questions

One of 392 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 →

How Courseiva writes practice questions · Editorial policy

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.