Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

An administrator wants to use Ansible to ensure a service is running on a remote host. Which Ansible module should be used in a playbook?

⚠ Common exam trap

XK0-006 often tests module selection by scenario — candidates confuse 'command'/'shell' (arbitrary execution, non-idempotent) with 'service' (idempotent service state management), picking command because it 'can run systemctl'.

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

✓

service

The Ansible 'service' module is designed to manage services on remote hosts — starting, stopping, restarting, and enabling them. To ensure a service is running, you use 'service' with state: started (and optionally enabled: yes). It abstracts underlying init systems (systemd, SysV, upstart) so the playbook works across distributions.

Answer analysis

Option-by-option breakdown

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

  • ✓

    service

    Why this is correct

    The service module manages systemd, sysvinit and similar service managers on the remote host, letting the playbook assert that a named service is started and enabled. It is the purpose-built module for service state, unlike command or shell, which would run arbitrary commands without idempotent state guarantees.

  • ✗

    command

    Why it's wrong here

    The command module runs arbitrary commands without idempotence, so it cannot guarantee the service remains running on subsequent runs. It is tempting for quick one-off tasks, but service state management requires the dedicated service module, which reports and enforces the desired state.

  • ✗

    copy

    Why it's wrong here

    The copy module transfers files to remote hosts and has no mechanism to start or verify a service's running state. It is tempting when deploying configuration files, but the question requires enforcing service state, which the service module handles declaratively.

  • ✗

    shell

    Why it's wrong here

    The shell module executes commands through a shell without idempotent state tracking, so repeated runs cannot confirm the service is running. It is tempting when shell features like pipes are needed, but ensuring service state calls for the service module's declarative parameters.

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.