Courseiva
Automation, Orchestration, and ScriptinghardMultiple ChoiceObjective-mapped

XK0-006 Automation, Orchestration, and Scripting Practice Question

A system administrator is creating an Ansible playbook to deploy a web server on a group of hosts. The playbook needs to install the nginx package, start the service, and ensure it is enabled on boot. Which playbook structure is correct?

⚠ Common exam trap

Candidates often assume that because the service is managed by systemd, the 'systemd' module must be used. However, Ansible's 'service' module works with both SysV and systemd, and is the recommended module for managing services across all distributions.

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

--- - hosts: webservers tasks: - name: Install nginx apt: name: nginx state: present - name: Start and enable nginx service: name: nginx state: started enabled: yes

It uses the 'service' module, which abstracts away the underlying init system and works on both SysV init and systemd systems, making it the recommended cross-platform choice. Option B is incorrect because the 'systemd' module is specific to systemd-managed services; while it works on many modern Linux distributions, it may not be available on older systems, and the 'service' module is preferred for portability. Options C and D are incorrect: C uses raw 'command' and 'command' to run shell commands, bypassing Ansible's idempotency and module benefits; D uses 'yum' instead of 'apt', which is inconsistent with the Debian/Ubuntu context implied by the 'apt' module in the correct option.

Answer analysis

Option-by-option breakdown

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

  • --- - hosts: webservers tasks: - name: Install nginx apt: name: nginx state: present - name: Start and enable nginx service: name: nginx state: started enabled: yes

    Why this is correct

    Correct. Uses 'apt' to install nginx (implied Debian/Ubuntu) and 'service' module to start and enable it. The 'service' module works with both SysV and systemd, ensuring portability.

  • --- - hosts: webservers tasks: - name: Install nginx apt: name: nginx state: present - name: Start and enable nginx systemd: name: nginx state: started enabled: yes

    Why it's wrong here

    Incorrect. While 'systemd' module works on systemd-based systems, it is not as portable as 'service'. Ansible's 'service' module is the recommended cross-distribution choice for service management.

  • --- - hosts: webservers tasks: - name: Install nginx command: apt install -y nginx - name: Start nginx command: systemctl start nginx

    Why it's wrong here

    Incorrect. Using raw 'command' and 'command' modules bypasses Ansible's idempotency and module features, making the playbook less reliable and harder to maintain.

  • --- - hosts: webservers tasks: - name: Install nginx yum: name: nginx state: present - name: Start and enable nginx service: name: nginx state: started enabled: yes

    Why it's wrong here

    Incorrect. The 'yum' module is for Red Hat–based distributions, but the correct playbook uses 'apt', implying Debian/Ubuntu. Mixing package managers is inconsistent.

About these practice questions

One of 979 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.