Install Ansible systemd service

I want to install the systemd service from a Jinja2 template. How to do it?

Do I have a copy module to copy a file to /lib/systemd/system and then use the systemd module to enable it?

Is there a better way?

+5
source share
1 answer

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

Using the systemd module with which I could start the service, I have to start the daemon_reload=yes .

Before Ansible 2.2 : after that I can do systemctl daemon-reload (for this, perhaps use the ansible handler for this) so that prod systemd picks up a 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 
+14
source

Source: https://habr.com/ru/post/1258414/


All Articles