EX294 Manage inventories and credentials Practice Question
Exhibit
Refer to the exhibit.
---
- name: Generate inventory
hosts: localhost
gather_facts: no
tasks:
- name: Create static inventory
add_host:
name: "web{{ item }}"
group: webservers
ansible_host: "192.168.1.{{ item }}"
loop:
- 10
- 11
- 12
- name: Create dynamic group
group_by:
key: "os_{{ ansible_distribution }}"
when: ansible_distribution is defined
---
# inventory.yml
plugin: constructed
strict: false
keyed_groups:
- key: ansible_distribution
prefix: distro
separator: "_"Refer to the exhibit. A user runs a playbook that creates hosts and then attempts to use a constructed inventory plugin. However, the constructed inventory does not group hosts by OS distribution. What is the most likely cause?
⚠ Common exam trap
Red Hat often tests the misconception that inventory plugins and dynamic host creation (`add_host`) operate in the same phase, when in fact the constructed plugin runs during inventory loading (pre-task) while `add_host` runs during task execution, creating a timing mismatch that candidates overlook.
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
✓
The constructed inventory runs before add_host tasks, so the hosts are not yet created.
The constructed inventory plugin processes inventory sources and applies Jinja2 conditions to group hosts based on variables. However, when used in a playbook alongside the `add_host` module, the constructed inventory is evaluated at the start of the play, before any tasks (including `add_host`) run. Therefore, hosts added dynamically via `add_host` do not exist when the constructed plugin attempts to group them, causing the groups to be empty. Option C correctly identifies this ordering issue.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The constructed plugin cannot be used with the add_host module.
Why it's wrong here
The constructed inventory plugin reads variables from existing inventory sources; hosts added at runtime by add_host exist only in memory for that play and are never persisted to an inventory source the plugin parses. It is tempting because add_host genuinely creates hosts dynamically, but those hosts are unavailable to inventory plugins.
- ✗
The 'strict: false' setting ignores missing variables, causing the group to be empty.
Why it's wrong here
strict: false only controls whether the plugin errors on undefined variables in its expressions; it does not empty groups that match valid variables, so grouping by ansible_distribution would still succeed. It is tempting because strict settings do affect plugin error behaviour, but they are not the cause of missing groups here.
- ✓
The constructed inventory runs before add_host tasks, so the hosts are not yet created.
Why this is correct
Constructed inventory plugins parse existing inventory sources at the start of a play; hosts added mid-play via add_host exist only in memory and are never written back. Because the inventory is built before those tasks execute, the OS distribution groups cannot be populated.
- ✗
The variable ansible_distribution is not defined because gather_facts is set to no.
Why it's wrong here
gather_facts on the play does not populate variables for the constructed inventory plugin, which reads its variables from inventory sources rather than from fact gathering during a play run. It is tempting because ansible_distribution is indeed a fact, but the plugin needs it present in inventory data, not gathered at play time.
Go deeper
Related to this question
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 →
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.