How can I find out which init Ansible system starts when I use the "service" module?

From the Ansible documentation , utility module:

Manages services on remote hosts. Supported initialization systems include BSD init, OpenRC, SysV, Solaris SMF, systemd, upstart.

For a given machine, how can I determine which init Ansible system is using? For example, a system may have init and systemd, for example.

+6
source share
2 answers

Take a look at the code modules:

Inside def main(): ::

 # Find service management tools service.get_service_tools() 

Then to class LinuxService(Service): and 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 cut some code, but this snippet should answer your question: which Ansible system can choose if there are a lot of them.

Systemd is the first to search, then pop up, etc.

+3
source

The init system on the host is available as Ansible fact ansible_service_mgr .

+8
source

All Articles