Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let ansible to use service instead of systemctl?

Tags:

ansible

I am using ansible service module to restart a system service. Below is the configuration of ansible file. When I run ansible command I got an error related to systemctl. Since my service is configured to run with service command instead of systemctl, I want ansible to use service command to start my service. Is there a way to configure ansible for that?

- name: start cooltoo_storage service
sudo: yes
service:
  name: cooltoo_storage
  state: started

I got below error when run systemctl. And I don't want to configure my service to be running with systemctl.

Job for cooltoo_storage.service failed because the control process exited with error code. See "systemctl status cooltoo_storage.service" and "journalctl -xe" for details.
like image 950
Joey Yi Zhao Avatar asked May 03 '16 09:05

Joey Yi Zhao


People also ask

How do I run an ansible service?

How to start a service. Set the name parameter to the service name and the state parameter to started to start a service. If the service is already running, Ansible will do nothing.

How do I know if a service is running ansible?

Just run the task service: name=httpd state=started with the option --check . This tells you, if the service needs to be started, which means that it is down. If the task shows no change, it is up already. Save this answer.

What is the difference between Systemd and Systemctl?

systemctl is used to examine and control the state of “systemd” system and service manager. systemd is system and service manager for Unix like operating systems(most of the distributions, not all).

What are services in ansible?

string. added in 2.2 of ansible.builtin. The service module actually uses system specific modules, normally through auto detection, this setting can force a specific module. Normally it uses the value of the 'ansible_service_mgr' fact and falls back to the old 'service' module when none matching is found. Default: “ ...


1 Answers

This is ansible 2.2, so above that this should work:

- name: start cooltoo_storage service
  sudo: yes
  service:
    name: cooltoo_storage
    state: started
    use: service

Basically the default value of 'use' is auto and it uses the system default service manager interface (eg. systemctl). You can override this when you know for sure that the system has 'service' command for example.

Details are found in the docs: https://docs.ansible.com/ansible/latest/service_module.html

like image 64
reegnz Avatar answered Sep 28 '22 10:09

reegnz