CertGrid CertGrid
Hands-on Lab·Ansible

Ansible Service State and Enablement

Two independent questions - is it running now, and will it run after a reboot - and two independent parameters. Then the one that catches everyone: systemd caches unit files, so writing a new one changes nothing until daemon_reload. This installs a real unit, proves the caching, and covers the states that can never be idempotent.

Automating Administration Guide 30 of 45 Intermediate

This lab is Ubuntu 26.04 and EX294 is a RHEL exam. systemd is the same on both, so this guide is one of the few in this track that is unchanged for EX294. ansible.builtin.service is the generic module; systemd_service is the systemd-specific one and the only one with daemon_reload.

One managed node. A `demoapp` unit is installed and removed again at the end.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-A01192.168.0.37Ubuntu 26.04 LTSManaged Node (group: web)2 Core3 GB50 GB

This guide includes

Use this when a service works today and is gone after a reboot. This matters because running now and starting at boot are two independent questions - and restarted is never idempotent.

Before you start

  1. The configuration this guide assumes

  2. started and enabled are two different questions

  3. A unit file of your own

  4. What happens without daemon_reload

  5. restarted is never idempotent

  6. Asking what is running

Official sources