restart server + check if service is started

1,172 views
Skip to first unread message

Mark van der Hout

unread,
Jun 5, 2014, 4:05:59 AM6/5/14
to ansible...@googlegroups.com
Hi,
Kinda new to Ansible and I'm struggling with the following:

I want to update a MYSQL server -> httpd -> varnish server. in that order.
I want to check, after the server rebooted, if the service mysqld or httpd is started before I continue with the httpd or varnish server.
Right now I have this but the post task runs way to fast before the server is restarted so it returns that the service is started:
Following is a code snippit, for the app server i instructed it to wait for port 80 and service httpd. but its the same.

Question is: How do I check if the server and service is up and running before I continue with the other servers in the playbook.
Thanks!

- hosts: dbservers
  user: root
  serial: 1

  tasks:
  - name: upgrade all packages + when done restart server
    yum: name=* state=latest
    notify:
    - restart server db
  handlers:
   - name: restart server db
     command: reboot

  post_tasks:
  - name: wait for db server to come up
    wait_for: host={{ inventory_hostname }} port=3306 state=started timeout=80
  - name: make sure mysql is started
    service: name=mysqld state=started

James Cammarata

unread,
Jun 5, 2014, 12:19:01 PM6/5/14
to ansible...@googlegroups.com
I'm guessing that what's going on here is that you're rebooting, but during the shutdown the mysql service is still running and port 3306 is up, so that when it gets to the wait_for task it succeeds and moves on. You may either want to add in a pause there before the wait_for, or you can add in a delay to the wait_for to cause it to delay its first polling attempt.

Hope that helps!


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/dbf7d673-c388-455d-af2c-06dcfb4b47f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Serge van Ginderachter

unread,
Jun 5, 2014, 2:41:53 PM6/5/14
to ansible...@googlegroups.com

On 5 June 2014 18:18, James Cammarata <jcamm...@ansible.com> wrote:
I'm guessing that what's going on here is that you're rebooting, but during the shutdown the mysql service is still running and port 3306 is up, so that when it gets to the wait_for task it succeeds and moves on. You may either want to add in a pause there before the wait_for, or you can add in a delay to the wait_for to cause it to delay its first polling attempt.

​Or do a wait_for state=stopped and then the same but with state=started.

If you want to check on a particular name in the process list to go away, then to re-appear, you might want to have a look at this module:





Serge

    ​

Mark van der Hout

unread,
Jun 5, 2014, 5:00:13 PM6/5/14
to ansible...@googlegroups.com
I see now that I missed the delay argument in the wait for port.
I already figured out the wait for stopped service.

Thanks a lot for the quick and clean responses from you both!


Op donderdag 5 juni 2014 20:41:53 UTC+2 schreef Serge van Ginderachter:
Reply all
Reply to author
Forward
0 new messages