how to collapse multiple restarts?

55 views
Skip to first unread message

pcorchary .

unread,
Jun 30, 2014, 7:12:15 PM6/30/14
to ansible...@googlegroups.com

In the snippet below, Am I right that elastic serach would be restarted 3 times assuming each action is performed?

Is there a way to collapse this into just one restart?

Say some way to set a flag for each action if the action is executed, and the at the end run a conditional to check if the flag >1 and then run the restart handler? 

- name: elasticsearch | write java server wrapper from template, restart ES
      action: template src=templates/elasticsearch_service_wrapper.j2 dest=${deploy_base}/elasticsearch-${elasticsearch.version}/bin/service/elasticsearch mode=0755
     tags:
        - configuration
      notify:
        -  Restart elasticsearch

- name: elasticsearch | Install config from templates, then restart ES
      action: template src=templates/$item dest=${deploy_base}/elasticsearch-${elasticsearch.version}/config/$item mode=0644 owner=root group=root
      with_items:
        - logging.yml
        - elasticsearch.yml
      tags:
        - configuration
      notify:
        - Restart elasticsearch

 - name: elasticsearch | Install upstart start script (conf) from templates, then restart ES
     action: template src=templates/elasticsearch.conf.initd.j2 dest=/etc/init/elasticsearch.conf
      notify:
        - Restart elasticsearch

 Thanks!

Michael DeHaan

unread,
Jun 30, 2014, 7:20:28 PM6/30/14
to ansible...@googlegroups.com
"In the snippet below, Am I right that elastic serach would be restarted 3 times assuming each action is performed?"

Nope.

Ansible will only run handlers in certain places (between pre_tasks and roles/tasks, and before post_tasks), unless there is a task that says

"- meta: flush_handlers".

This is an easy experiment to try on your own and you should observe this.

pre_tasks and post_tasks are mainly of use for rolling update plays with load balancer or monitoring remove/add type steps, and can usually be ignored if you are not doing these things.






--
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/6853692e-ea81-4a9b-8fcb-cc49e247bbea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pcorchary .

unread,
Jun 30, 2014, 7:24:37 PM6/30/14
to ansible...@googlegroups.com


Oops. My mistake.

I should RTFM.
<<

Handlers are lists of tasks, not really any different from regular tasks, that are referenced by name. Handlers are what notifiers notify. If nothing notifies a handler, it will not run. Regardless of how many things notify a handler, it will run only once, after all of the tasks complete in a particular play.
>>

Thanks Michael
Reply all
Reply to author
Forward
0 new messages