How can I install a systemd service using Ansible?

I use the template module to install the .service file into the /etc/systemd/system. According to this digital ocean blog post /lib/systemd/system should be reserved for packages bundled with the OS itself, and third party services should be defined in /etc/systemd/system.

With ansible’s systemd module I’d start the service with daemon_reload=yes.

Prior to Ansible 2.2: I do a systemctl daemon-reload afterward (can use an ansible handler for this if appropriate) to prod systemd to pick up the new file.

- name: install myservice systemd unit file
  template: src=myservice.j2 dest=/etc/systemd/system/myservice.service

- name: start myservice
  systemd: state=started name=myservice daemon_reload=yes


# For ansilble < 2.2 only
#- name: reload systemd unit configuration
#  command: systemctl daemon-reload

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)