Interview Prep/Ansible/Ad-hoc Commands, Modules and Idempotency

How do `service` and `systemd` modules differ?

IntermediateConceptAd-hoc Commands, Modules and Idempotency
Answer

service is a generic wrapper that picks systemd, SysV or others. systemd_service (alias systemd) is specific to systemd and adds daemon_reload, masked, scope: user and enabled control.

- ansible.builtin.systemd_service:
    name: myapp
    state: restarted
    enabled: true
    daemon_reload: true

Run daemon_reload after dropping a new unit file, or systemd will keep using the old definition. In containers without systemd the modules fail, which is a common surprise in Molecule tests.

All Ansible questions Roadmap: Ansible

More on Ad-hoc Commands, Modules and Idempotency