0Pricing
Ansible Academy · Lesson

Manage Services with systemd

Start, stop and enable services.

Manage Services with systemd is a free Ansible Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Manage Long-Running Services

The systemd module controls services managed by systemd, the init system on most modern Linux distros. You start, stop, and enable them with it.

Start a Service

Give the service name and set state: started. The module starts it only if it is not already running, staying idempotent.

ansible.builtin.systemd:
  name: nginx
  state: started

Stop a Service

Use state: stopped to bring a service down. As always, it only acts if the service is currently running.

ansible.builtin.systemd:
  name: nginx
  state: stopped

Restart and Reload

state: restarted fully restarts a service, while reloaded re-reads config without dropping connections. Restart is the safe default.

ansible.builtin.systemd:
  name: nginx
  state: restarted

Start vs Enable Are Different

state controls if a service runs right now. enabled controls whether it starts automatically on boot. They are independent.

Enable at Boot

Set enabled: true so the service launches automatically after a reboot. Combine it with started to cover both now and later.

ansible.builtin.systemd:
  name: nginx
  state: started
  enabled: true

Reload the systemd Daemon

After adding a new unit file, set daemon_reload: true so systemd re-reads its configuration before you act on the unit.

ansible.builtin.systemd:
  name: myapp
  daemon_reload: true

It Stays Idempotent

Ask for started on a running service and you get ok, not changed. The module checks the live state before doing anything.

Root Access Is Required

Controlling services needs privileges, so add become: true. Without it, systemd refuses and the task fails.

- name: Enable nginx
  become: true
  ansible.builtin.systemd:
    name: nginx
    enabled: true

There Is Also the service Module

The generic service module works across init systems. Use systemd directly when you need systemd-only options like daemon_reload.

Pairs Well With Handlers

A common pattern is to restart a service only when its config changes. Handlers, which you meet later, trigger this restart on change.

Quick Check

You want nginx running now and also after every reboot.

Recap

The systemd module starts, stops, restarts, and enables services. Remember that state means now and enabled means on boot. ⚙️

Frequently asked questions

Is the “Manage Services with systemd” lesson free?

Yes — the full text of “Manage Services with systemd” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.

What will I learn in “Manage Services with systemd”?

Start, stop and enable services. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Ansible Academy?

No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Manage Services with systemd” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Ansible Academy lesson?

Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What a Module Actually Is
  2. Install Packages with the package Module
  3. Manage Services with systemd
  4. Read the Docs with ansible-doc
← Back to Ansible Academy