XK0-006 Automation, Orchestration, and Scripting Practice Question
A Linux administrator uses Ansible to manage a fleet of servers and needs to ensure a configuration file is present with specific contents on all web servers, restarting the service only when the file changes. Which Ansible module and handler pattern accomplishes this?
⚠ Common exam trap
The trap here is assuming that restarting the service in the same task or unconditionally is equivalent to using a handler, which only fires on change.
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
✓
Use the `copy` module with a `notify` directive that triggers a handler containing the `service` module with `state: restarted`
Idempotent configuration management requires a module that reports change status and a handler that reacts to that status. The `copy` module writes the file and reports changed only on difference, and the `notify` directive invokes a handler that restarts the service. Unconditional shell restarts, `force: no`, or timestamp-only modules all fail to deliver a restart triggered specifically by a content change.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use the `file` module with `state: touch` and a `cron` job to restart the service periodically
Why it's wrong here
`state: touch` only updates timestamps and does not manage file contents, so the required configuration would never be written. A periodic cron restart is unrelated to change detection and would restart the service on a fixed schedule regardless of whether anything changed. This approach fails to manage content and violates the change-driven restart requirement.
- ✗
Use the `template` module with `force: no` and no handler, relying on the service to reload automatically
Why it's wrong here
Setting `force: no` prevents the file from being updated if it already exists, so content changes would never be applied. Relying on automatic reload assumes the service watches its configuration, which most services do not. Without a handler, no restart is triggered, so the new configuration would not take effect.
- ✓
Use the `copy` module with a `notify` directive that triggers a handler containing the `service` module with `state: restarted`
Why this is correct
The `copy` module places the file with the specified content and reports a changed status only when the content differs. The `notify` directive then triggers the named handler, which uses the `service` module to restart the web service. This ensures the restart occurs only on change, matching the requirement exactly.
- ✗
Use the `shell` module to run `systemctl restart httpd` after writing the file with a `command` task
Why it's wrong here
Running `systemctl restart` unconditionally restarts the service on every playbook run, regardless of whether the configuration file changed. The `shell` and `command` modules also bypass idempotency and change reporting. This does not meet the requirement to restart only when the file changes and is not idiomatic Ansible.
Go deeper
Related to this question
Learn chapter
Installing Linux and Package Management
Key term
Shell
A shell is a computer program that provides a user interface to access an operating system's services, typically by accepting text commands.
Key term
Service
A service is a software component or system that performs a specific function and is available to be used by other programs or users over a network.
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.