XK0-006 Automation, Orchestration, and Scripting Practice Question
A Linux administrator uses Ansible to configure a fleet of web servers. A playbook task must copy a template file and then restart the nginx service only when the template content actually changes, avoiding needless restarts on every run. Which task construct enforces that behavior?
⚠ Common exam trap
The trap here is reaching for an unconditional service restart or a when condition, when only a notify-handler pair reacts to the change status of the template task.
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
✓
A template task with notify pointing to a handler that restarts nginx
Ansible handlers are triggered only when a task reports a changed result, and the template module reports changed precisely when the rendered output differs from the file on the managed host. Wiring notify to a handler that restarts nginx therefore produces a restart only on genuine configuration changes, keeping repeated playbook runs idempotent and quiet.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
A template task with notify pointing to a handler that restarts nginx
Why this is correct
The template module reports changed status only when the rendered file differs from the destination, and notify queues the named handler exclusively on that change. Handlers run once at the end of the play, so nginx restarts only after an actual template modification, which is exactly the idempotent behavior the scenario requires.
- ✗
A copy task with force: no followed by a shell task that runs systemctl restart nginx
Why it's wrong here
The copy module cannot render Jinja2 variables the way template does, so the configuration would be deployed literally. Even with force: no, the shell task restarts nginx on every run regardless of change, reintroducing the unnecessary restarts. Both the module choice and the lack of change gating are wrong.
- ✗
A template task with a when clause that checks whether the nginx process is running
Why it's wrong here
A when clause evaluates a condition before the task runs and has no awareness of whether the template content changed. Testing process state would either always copy or always skip, and it never triggers a restart based on file modification. The scenario needs change-driven notification, not a pre-run condition.
- ✗
A template task followed by a service task with state: restarted and no conditional
Why it's wrong here
An unconditional service task with state restarted bounces nginx on every playbook execution whether or not the template changed. That defeats the goal of avoiding needless restarts and breaks idempotence reporting, since the play always records a change. It ignores the change status that the template module already tracks.
Go deeper
Related to this question
Learn chapter
Linux Fundamentals and History
Key term
Linux
Linux is an open-source operating system that manages computer hardware and software, widely used in servers, desktops, and embedded systems.
Key term
Output
In IT service management, output is the result or deliverable produced by a process, system, or component, such as data, reports, or services delivered to a customer.
About these practice questions
This XK0-006 question is part of Courseiva's 781-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 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.