0

I'm coming from the Docker side of things. Managing "services" is rather simple. 1 "service" = 1 container. Ensuring that a service is running at startup is easy with Ansible.

But when it comes to managing services on a Debian/Ubuntu based Linux machine, I know there's systemd. But I can't find a proper Ansible module to define services and ensure that they run on startup. How can I achieve that?

shellwhale
  • 820
  • 1
  • 10
  • 34

1 Answers1

2

Your question is very vague and does not provide much information. However, regarding

... I can't find a proper Ansible module to define services ...

you may have a look into the documentation of the systemd_module.

To

... ensure that they run on startup ...

you could use something like

- name: Make sure {{ SERVICE }} is started and enabled
  systemd:
    name: "{{ SERVICE }}"
    state: started
    enabled: true

To be able to start and enable a "service" via the systemd_module you'll need just a systemd service file.

Further Documentation

One example for creating and managing a simple service is

U880D
  • 8,601
  • 6
  • 24
  • 40
  • I already saw these modules, I can't create a new services with them. I can only manage existing ones. – shellwhale Jan 11 '22 at 19:00
  • @shellwhale, can you provide a minimal example what do mean by creating new "services" or describe your problem much more detailed? – U880D Jan 11 '22 at 19:04
  • I'm simply looking to run a binary on startup. Syncthing more precisely https://docs.syncthing.net/users/autostart.html#linux – shellwhale Jan 11 '22 at 19:44
  • @shellwhale, I see, it is quite similar to the already provided `node_exporter` example. And the from you mentioned `syncthing` documentation has all information which is necessary to make a "service" from. – U880D Jan 11 '22 at 19:56
  • I see thank you. I was expecting a module to add new units but it looks like copying a file is enough. – shellwhale Jan 11 '22 at 20:30