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.
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.
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.
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).
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: “ ...
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
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