Starting sysv service when systemd is installed

Say my target machine has an OS running systemd, like CentOS 7, and I want to start a sysv service in /etc/init.d.

These tickets suggest I pass use=service to the service module:

https://github.com/ansible/ansible-modules-core/issues/915

https://github.com/ansible/ansible/issues/25440

This used to work on Ansible 2.2, but no longer seems to work in 2.4. Is there a different way?

  • name: start foo service

service: name=foo state=started enabled=yes use=service

This returns an error:

systemd could not find the requested service "‘foo’"

service module uses systemd if detected, its not a sysvinit module,
that is here https://github.com/ansible/ansible/pull/29158, in any
case, systemd is supposed to be able to handle init scripts.

So is that “use” parameter no longer valid? It should probably be removed from the documentation. I didn’t see this mentioned in the Ansible 2.4 changelog or porting guide.

The use parameter is still valid, it lets you override the selection,
but the 'use=service' defaults to the 'old ansible service module' ,
which still does it's own autodetection and uses systemd if present
(it always did).

It does NOT use the 'service' command, which varies by distro/OS and
has diff implementations, though the service plugin can use it, it is
not what the `use` parameter does.

I see, thanks. Not sure how I got it to work before with use=service, unless maybe the service module’s auto-detection method changed since 2.2. Anyway, I guess I can work around it with “command” for now, until there’s a sysv module available.