Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

An administrator wants to run a script on multiple remote servers using Ansible. The script requires a variable that differs per host. Where should the administrator define this variable to follow best practices?

⚠ Common exam trap

XK0-006 often tests Ansible variable precedence and file layout — candidates pick group_vars/all.yml because it is 'centralised', but that applies to all hosts, not per-host as the question requires.

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 host_vars/<hostname>.yml

Ansible best practice is to define host-specific variables in host_vars/<hostname>.yml, where the filename matches the inventory hostname. This keeps per-host configuration separate from the playbook and inventory, making it easy to maintain, version-control, and override at the appropriate precedence level. Variables defined here automatically apply only to that host, which is exactly what the scenario requires.

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 playbook under vars:

    Why it's wrong here

    Playbook-level vars: apply one value to every host in the play, so the per-host variation cannot be represented. It is tempting because declaring variables beside tasks keeps a playbook self-contained, and it would be correct when the value is constant for all hosts in that play.

  • ✓

    In host_vars/<hostname>.yml

    Why this is correct

    Host-specific variables belong in host_vars/<hostname>.yml, which Ansible loads automatically for that inventory host. This keeps per-host values isolated from group and playbook scope, so the differing variable is applied only to the intended server without overriding other hosts' configuration.

  • ✗

    In the inventory file as a variable

    Why it's wrong here

    An inventory variable attached to a host entry defines the value for that host, but the stem asks for best practice, which places host-specific data in host_vars. It is tempting because inventory variables are quick to add, and it would be correct for connection settings such as ansible_host or ansible_user.

  • ✗

    In group_vars/all.yml

    Why it's wrong here

    group_vars/all.yml applies one identical value to every host, so per-host differences cannot be expressed. It is tempting because group_vars is the standard location for shared settings, and it would be correct when a variable genuinely holds the same value across all managed hosts.

About these practice questions

Courseiva writes every XK0-006 question from scratch — 781 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 →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official CompTIA exam blueprint

This XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.