Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

I'm just getting my feet wet with Ansible 2.2 and Devops 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 the Ansibles service module to restart the server. However, that fails

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

unsupported parameter for module:sleep

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?

1 Answer

0 votes
by (50.2k points)

For this type of issue, you just add the following snippet to your playbook which will enable ansible to use service module instead of systemd.

- name: restart MySQL

  service: "name={{ mysql_daemon }} state=restarted"

  register: mysql_service

 

- name: pause after MySQL restart

  pause: "seconds=5"

  when: mysql_service.changed

Add this to your play-book then you can see the ansible working from the service module.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...