From the Ansible documentation, the service module:
Controls services on remote hosts. Supported init systems include BSD init, OpenRC, SysV, Solaris SMF, systemd, upstart.
For a given machine, how can I tell which init system Ansible is using? A system may have init and systemd on it, for example.
Just run the task service: name=httpd state=started with the option --check .
What does the Ansible service module do? Ansible's service module controls services on remote hosts and is useful for these common tasks: Start, stop or restart a service on a remote host.
Use systemctl restart ansible-tower to restart services on clustered environments instead. Also you must restart each cluster node for certain changes to persist as opposed to a single node for a localhost install.
The init system on a host is available as Ansible fact ansible_service_mgr
.
Let's look into the modules' code:
Inside def main():
:
# Find service management tools
service.get_service_tools()
Then to class LinuxService(Service):
and to def get_service_tools(self):
# Locate a tool to enable/disable a service
if check_systemd():
# service is managed by systemd
...
elif location.get('initctl', False) and os.path.exists("/etc/init/%s.conf" % self.name):
# service is managed by upstart
...
elif location.get('rc-service', False):
# service is managed by OpenRC
...
elif self.svc_initscript:
# service is managed by with SysV init scripts
...
I've cut some code, but this snippet should answer your question: what system Ansible is likely to choose if there are many.
Systemd is the first one to search, then upstart, etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With