Define one notification block for multiple tasks in Ansible

Is it possible to define one block notifyfor several tasks?

The following code snippet notify: restart tomcatis set 3 times, but I want to define it only once and "apply" to the task list

- 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
+4
source share
2 answers

No, you can’t.

Notify sets a trigger to start the specified handler depending on the state of the task. Ansible does not have a "status for a task block", so you cannot define notifyfor a block.

, , ( , , ). , , .

+6

, .

- include: role2.yml

2

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

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

- 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

- name: running handler for above tasks
  debug: msg='running handler for all three'
  notify: restart tomcat
-2

Source: https://habr.com/ru/post/1666605/


All Articles