Search code examples
ansiblesystemd

Does Ansible's systemd module a `daemon-reload` before starting a service?


I have a playbook where I first copy a new service file to /etc/systemd/system/ and then start the service. Normally, I'd have to run sudo systemctl daemon-reload before starting the service.

There is a daemon_reload parameter to the systemd module, but the description is not clear. It says "When set to true, runs daemon-reload even if the module does not start or stop anything." It sounds like it usually runs daemon-reload before starting or stopping services, and that this switch just makes it run daemon-reload always even when there's no state change.

Example of what I'm doing:

- name: Install Foo
  hosts: all
  tasks:
    - name: Install SystemD service
      become: true
      copy:
        src: ./foo.service
        dest: /etc/systemd/system/
    - name: Ensure the service is running
      become: true
      systemd:
        name: mqtt-button.service
        enabled: true
        state: started

Solution

  • Ansible does not implicitly run systemctl daemon-reload.

    It only runs it when you set daemon_reload: true, but in this case it will run the daemon-reload command regardless of whether or not it needs to start or stop any services.

    When in doubt about the documentation you can always refer to the source.