EX294 Manage inventories and credentials Practice Question
An inventory is sourced from an external dynamic inventory plugin. The plugin returns hosts with groups including 'webservers' and 'dbservers'. An administrator wants to add a custom variable to all hosts in the 'webservers' group without modifying the plugin script. How can this be achieved?
⚠ Common exam trap
Candidates often think modifying the plugin script (Option A) is acceptable, but the EX294 exam emphasizes immutability of external sources and using Ansible's built-in variable precedence and group_vars instead.
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
✓
Create a group_vars file named 'webservers' in the project directory and define the variable
Ansible's group_vars mechanism allows you to define variables for all hosts in a group by creating a YAML file named after the group (e.g., 'webservers') in the group_vars directory. This approach does not require modifying the dynamic inventory plugin script, which is external and should remain untouched. The variable will be automatically applied to all hosts in the 'webservers' group during playbook execution.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Modify the dynamic inventory plugin script to add the variable
Why it's wrong here
Editing the plugin script directly contradicts the requirement not to modify it, and the change would be overwritten whenever the plugin is updated or replaced. It is tempting because the plugin defines the groups, but it would be correct only when the plugin itself is the maintained source of truth.
- ✗
Add the variable to the host_vars file for each host
Why it's wrong here
host_vars files apply variables per individual host, so they cannot set one value across every member of the webservers group, and each host would need its own file. It is tempting for host-specific overrides, but it would be correct when a single host needs a variable differing from its group.
- ✓
Create a group_vars file named 'webservers' in the project directory and define the variable
Why this is correct
Group_vars files are loaded automatically by Ansible from the project directory and override or supplement plugin-supplied group data, so defining 'webservers' there injects the custom variable into every host in that group without touching the dynamic inventory script.
- ✗
Use the 'add_host' module in a playbook to set the variable
Why it's wrong here
add_host adds new hosts to the in-memory inventory during a play; it does not assign variables to hosts already returned by the dynamic plugin, and the group would not be populated. It is tempting for runtime host registration, but it would be correct when provisioning new instances mid-playbook.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX294 question from scratch — 392 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.