Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define one notify block for several tasks in Ansible

Tags:

ansible

Is it possible to define one notify block for several tasks?

In next code snippet notify: restart tomcat defined 3 times, but I want to define it only one time and "apply" to list of tasks

- name : template context.xml
  template:
    src: context.xml.j2
    dest: /usr/share/tomcat/conf/context.xml
    group: tomcat
    mode: 0664
  notify: restart tomcat

- name : copy server.xml
  copy:
    src: server.xml
    dest: /etc/tomcat/server.xml
    group: tomcat
    mode: 0664
  notify: restart tomcat

- name : copy atomikos-integration-extension
  copy:
    src: atomikos-integration-extension-3.7.1-20120529.jar
    dest: /usr/share/tomcat/ext-libs/
    group: tomcat
    mode: 0664
  notify: restart tomcat
like image 204
qwazer Avatar asked Jan 12 '17 12:01

qwazer


1 Answers

No, you cannot.

Notify sets a trigger to run the specified handler based on the status of the task. There is no "status for a block of tasks" in Ansible hence you cannot define notify for a block.

Besides, it wouldn't change anything functionally, only influence the visual appeal (and I would claim by obscuring things rather than simplifying). The handler is run only once regardless of how many tasks triggered it.

like image 64
techraf Avatar answered Sep 21 '22 07:09

techraf