EX294 Implement advanced Ansible automation Practice Question
An Ansible playbook includes a role that defines default variables in 'defaults/main.yml' and role variables in 'vars/main.yml'. A playbook sets the same variable in the play's 'vars' section. Which variable value takes precedence?
⚠ Common exam trap
Red Hat often tests the misconception that role vars override play vars because they are defined inside the role, but the actual precedence places play vars above role vars, so candidates must memorize the full variable precedence order to avoid this trap.
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
✓
Play vars
In Ansible, variable precedence is hierarchical, and play vars (set directly in the play's `vars` section) have a higher priority than role defaults and role vars. Specifically, play vars override role vars, which in turn override role defaults. Therefore, when the same variable is defined in all three locations, the play vars value takes precedence.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Role defaults
Why it's wrong here
Role defaults sit at the bottom of Ansible's precedence order, so any play-level vars entry overrides them. It tempts because defaults are the role author's intended baseline, and they do win when no other definition exists anywhere in the play.
- ✗
Inventory group vars
Why it's wrong here
Inventory group vars lose to play vars, role vars and role defaults, so they cannot outrank a play-level definition. They are tempting because they correctly override role defaults and role vars for hosts in a group, which suits environment-wide settings such as package versions across a server fleet.
- ✗
Role vars
Why it's wrong here
Play vars override role vars, so the playbook's value wins, not the role's. Role vars sit above defaults but below play vars in Ansible's precedence order. Choosing this confuses role vars with the highest-precedence source; role vars would win only if the play set nothing.
- ✓
Play vars
Why this is correct
Play vars outrank both role defaults and role vars in Ansible's precedence order, sitting above role vars/main.yml and far above defaults/main.yml. Because the play explicitly sets the variable, that value overrides the role's defaults and vars, satisfying the stem's precedence question.
Go deeper
Related to this question
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 →
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.