Courseiva

EX294 Implement advanced Ansible automation Practice Question

Which three methods can be used to pass variables to an Ansible playbook? (Select exactly 3.)

⚠ Common exam trap

Candidates often confuse role-level variable files (like `vars/main.yml`) with playbook-level variable passing methods, or mistakenly think that `ansible.cfg` can hold variables, when in fact it only holds configuration directives.

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

✓

In the playbook's vars_files directive.

The `vars_files` directive in a playbook allows you to specify external YAML or JSON files containing variables, which are then merged into the play's variable scope at runtime. This is a standard method for passing variables to a playbook, as it separates variable definitions from the playbook logic.

Answer analysis

Option-by-option breakdown

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

  • ✗

    In the ansible.cfg file.

    Why it's wrong here

    ansible.cfg does not support variable definitions for playbooks.

  • ✗

    In the role's vars/main.yml.

    Why it's wrong here

    Role vars are only available within that role's scope.

  • ✓

    In the playbook's vars_files directive.

    Why this is correct

    vars_files includes YAML/JSON files with variables.

  • ✓

    In the inventory file variables.

    Why this is correct

    Inventory can define host and group variables.

  • ✓

    Using the --extra-vars command line option.

    Why this is correct

    --extra-vars overrides other variables.

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

Same concept, more angles

1 more way this is tested on EX294

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Which three of the following are valid methods to pass variables to an Ansible playbook at runtime? (Choose three.)

medium
  • ✓ A.Using '--extra-vars' command line option.
  • B.Using '--ask-vault-pass' and storing variables in encrypted files.
  • C.Using 'environment' directive in the playbook.
  • ✓ D.Using 'vars_prompt' in the playbook.
  • ✓ E.Using '-e @file' to load variables from a JSON file.

Why A: The `--extra-vars` (or `-e`) command-line option allows you to pass variables directly to an Ansible playbook at runtime. This overrides any previously defined variables and can accept key=value pairs or load from JSON/YAML files, making it the primary method for runtime variable injection.

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.