Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

An Ansible playbook includes a handler that restarts a service when a configuration file is changed. Which directive in a task triggers the handler?

⚠ Common exam trap

The trap is confusing register: (capture output) or when: (conditional execution) with notify:, which is the only directive that actually triggers a handler.

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

✓

notify:

In Ansible, a task uses the notify: directive to name one or more handlers that should be triggered when that task reports a change (i.e., when the task's state is 'changed'). Handlers then run once at the end of the play, in the order they were notified, only if at least one notifying task changed.

Answer analysis

Option-by-option breakdown

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

  • ✗

    register:

    Why it's wrong here

    register: captures a task's return values into a variable for later use in conditionals or output; it never notifies a handler. It is the right directive when a subsequent task must test a result, such as checking command output before acting.

  • ✗

    when:

    Why it's wrong here

    when: applies a conditional that decides whether a task runs at all; it does not notify handlers. It is correct when execution depends on a variable or fact, such as running only on a particular OS family, not for triggering a restart after a config change.

  • ✗

    handlers:

    Why it's wrong here

    The handlers: directive declares the handler section and names handlers; it does not trigger them. Triggering occurs when a task reports changed status and lists notify. handlers: is correct for defining the restart task itself, not for invoking it from a changed configuration task.

  • ✓

    notify:

    Why this is correct

    The notify directive names the handler to trigger when a task reports changed state, so a config-file modification notifies the restart handler. Handlers run once at play end, avoiding repeated service restarts during the play.

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.