Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible using systemd instead of service module

Tags:

ansible

devops

I'm just getting my feet wet with Ansible 2.2 and Debops and I've run into the following problem. I have a host test-host to which I deployed a MySQL server (using geerlingguy.mysql).

The role uses the following handler to restart the service:

---
- name: restart mysql
  service: "name={{ mysql_daemon }} state=restarted sleep=5"

which, I thought, uses Ansibles service module to restart the server. However, that fails:

unsupported parameter for module: sleep

So just to rule out any weirdness with that custom role, I've tried to execute the module directly like so:

ansible test-host -b -m service -a 'name=mysql sleep=5 state=restarted'

with the same result.

Running Ansible with more verbose output shows (among other things):

Running systemd
Using module file /usr/local/lib/python2.7/site-packages/ansible-2.2.0-py2.7.egg/ansible/modules/core/system/systemd.py

So it appears that the systemd module is used instead of service (looking into the module shows that it is indeed aliased to service). And, lo and behold, systemd does not support the sleep parameter.

How to fix this?

like image 359
n3rd Avatar asked Jun 08 '16 11:06

n3rd


People also ask

What is SystemD in ansible?

Ansible SystemD module helps to control the systemd units such as services and timers created on the Linux server. SystemD is a daemon that manages the services and timer units on the Linux system and we mostly interact with it using the following ways. service file. systemctl command. journalctl command.

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.

What is daemon in ansible?

This daemon extends the ansible-pull method of running Ansible. It uses S3 or HTTP file transmission instead of Git to manage distribution (easy to cache), and integrates with Prometheus monitoring.

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. For more information on clustered environments, see the Clustering section.


1 Answers

You can workaround it by adding another step in your playbook like this:

- name: restart mysql
  service: "name={{ mysql_daemon }} state=restarted"
  register: mysql_service

- name: pause after mysql restart
  pause: "seconds=5"
  when: mysql_service.changed
like image 180
Jiri Klouda Avatar answered Sep 20 '22 07:09

Jiri Klouda