Courseiva

EX294 Implement advanced Ansible automation Practice Question

A playbook uses a loop over a list of packages to ensure they are installed. However, the playbook runs slowly because each package is processed individually. Which optimization technique should be used to improve performance?

⚠ Common exam trap

Candidates often confuse task-level parallelism (which Ansible does not natively support for loops) with host-level parallelism (controlled by 'serial' or 'strategy'), leading them to select options that seem to increase parallelism but do not apply to a single-host loop.

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

✓

Pass the entire list to the package module's 'name' parameter instead of looping.

Ansible's package modules (such as yum, apt, or dnf) accept a list of packages in the 'name' parameter. Passing the entire list in a single task eliminates the overhead of multiple task executions, SSH connection reuse, and module setup/teardown that occur with each iteration in a loop. This reduces the number of Ansible task runs from N to 1, significantly improving performance.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    Pass the entire list to the package module's 'name' parameter instead of looping.

    Why this is correct

    Passing the whole list to the package module's name parameter lets Ansible invoke the underlying package manager once for all packages, rather than spawning a separate module execution per item. This removes per-iteration overhead, directly addressing the slow loop described in the stem.

  • ✗

    Use with_items instead of loop; with_items is faster.

    Why it's wrong here

    with_items is legacy syntax that internally maps to loop; it offers no speed advantage and is deprecated in favour of loop. It remains useful only for maintaining older playbooks. Passing a list directly to the package module's name parameter is the actual optimisation.

  • ✗

    Set the async parameter on the looped task to run packages in parallel.

    Why it's wrong here

    Async parallelises a single task's execution, not loop iterations; each package still runs sequentially. It suits long-running single commands where the controller need not wait. Combining packages into one module call with a name list is what removes per-package overhead.

  • ✗

    Use the serial keyword at the play level to increase parallelism.

    Why it's wrong here

    serial controls how many hosts a play targets per batch, not iteration concurrency within one host's task. It is correct for rolling updates across many managed nodes. Here the bottleneck is per-package module invocations, which serial does nothing to reduce.

About these practice questions

This EX294 question is part of Courseiva's 392-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.