Search code examples
serviceansible

Can Ansible service-module be used for non-root daemons?


I need to ensure, a daemon is running, but I do not have root-access. The daemon itself does not need root anyway.

Is there a way to use Ansible's service-module somehow -- for readability -- or do I need to do it all "by hand" (with shell and command modules)?

The module's description does not seem to provide for this except for the use-clause. Can one implement a custom service-module for manipulating the service? How?


Solution

  • At least, when the service-provider is systemd, this is, indeed, possible. Use the systemd-module and set scope:

    - name: Enable service FOO
      systemd:
        name: FOO.service
        enabled: true
        scope: user
    

    Note, that the ~/.config/systemd/user/FOO.service has to already exist.

    And then you have to have systemd-support for users' own services -- which on RedHat, for example, is only officially available since RedHat-8 (unofficially you can enable it in RedHat-7, but that's a separate story).

    Once configured, you'll need to use the --user switch with systemctl to manipulate the service:

    systemctl --user status FOO