Thursday, 15 March 2012

How to handle changes to init scripts in Ansible? -



How to handle changes to init scripts in Ansible? -

i'm relatively new ansible , i've created playbook can install tomcat configuration on 'bare' server. i'm wondering how solve problem of beingness able update init.d script while avoiding stop service @ start of playbook when there no alter in script. here's basic playbook:

- name: stop tomcat service service: name=my_service state=stopped - name: re-create init.d script template: src=script.j2 dest=/etc/init.d/my_service - name: other tasks here - name: start tomcat service service: name=my_service state=restarted

this playbook stop , start service, if there no changes. want playbook stop , start service when there actual changes.

i know utilize handlers (need more), need stop service using old init.d script, before copying new script. afaik handlers respond result of task after action has taken place, mean new script copied on old 1 , might prevent service stopping , restarting.

how handle that?

any task set notify handler @ end of play.

http://docs.ansible.com/playbooks_best_practices.html#task-and-handler-organization-for-a-role

- name: re-create init.d script template: src=script.j2 dest=/etc/init.d/my_service notify: start tomcat service handlers: - name: start tomcat service service: name=my_service state=restarted

you may want have play work old script handler stops services old script, , different play copying new script handlers.

init ansible ansible-playbook

No comments:

Post a Comment