We have one Ansible role that needs to run three tasks in the handlers/main.yml task file, but it only runs the first task. How do I force it to run the other two tasks? I do have the ignore flag on for if the first task fails.
The tasks/main.yml file looks like:
- name: openfire | Copy plugins into openfire/plugins   copy: src={{ srcdir }}/xmpp/{{ item }} dest=${bindir}/openfire/plugins/{{ item }}   with_items:    - x.jar    - y.jar   sudo: yes   sudo_user: ${tomcat_user}   notify: restart openfire  - name: openfire | Copy jars into openfire/lib   copy: src={{ srcdir }}/xmpp/{{ item }} dest=${bindir}/openfire/lib/{{ item }}   with_items:    - a.jar    - b.jar   sudo: yes   sudo_user: ${tomcat_user}   notify: restart openfire   The handlers/main.yml file looks like:
- name: restart openfire   service: name=openfire state=stopped   ignore_errors: true   sudo: yes  - name: restart openfire   file: path=/var/run/openfire.pid state=absent   sudo: yes  - name: restart openfire   service: name=openfire state=restarted enabled=yes   sudo: yes   Only the first handler task (shut down openfire) runs.
If you need to execute a task with Ansible more than once, write a playbook and put it under source control. Then you can use the playbook to push out new configuration or confirm the configuration of remote systems.
Handlers are executed in the order they are defined in the handlers section, not in the order listed in the notify statement. Notifying the same handler multiple times will result in executing the handler only once regardless of how many tasks notify it.
In a nutshell, handlers are special tasks that only get executed when triggered via the notify directive. Handlers are executed at the end of the play, once all tasks are finished. In Ansible, handlers are typically used to start, reload, restart, and stop services.
Its possible for handler to call another notify. Multiple notify calls are also allowed:
--- - name: restart something   command: shutdown.sh    notify:     - wait for stop     - start something     - wait for start  - name: wait for stop   wait_for: port={{port}} state=stopped  - name: start something   command: startup.sh  - name: wait for start   wait_for: port={{port}} state=started 
                        As of Ansible 2.2, you can now notify multiple handlers at the same time using the listen directive:
- name: stop openfire   listen: restart openfire   service: name=openfire state=stopped   ignore_errors: true   sudo: yes  - name: remove openfire pid file   listen: restart openfire   file: path=/var/run/openfire.pid state=absent   sudo: yes  - name: restart openfire   listen: restart openfire   service: name=openfire state=restarted enabled=yes   sudo: yes 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With