Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell which init system Ansible runs when I use the "service" module?

Tags:

init

ansible

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.

like image 210
Kevin Burke Avatar asked Sep 08 '16 15:09

Kevin Burke


People also ask

How do you check if a service is running using Ansible?

Just run the task service: name=httpd state=started with the option --check .

What is service module in Ansible?

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.

How do I start Ansible service?

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.


2 Answers

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

like image 81
Henrik Pingel Avatar answered Oct 07 '22 02:10

Henrik Pingel


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...

like image 32
Konstantin Suvorov Avatar answered Oct 07 '22 01:10

Konstantin Suvorov