Last active
April 20, 2021 14:55
-
-
Save pfuntner/526b7c397a714f3f4dd774bcbfc6c2e6 to your computer and use it in GitHub Desktop.
Running multiple tasks in an Ansible handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- block: | |
- name: message 1 | |
debug: msg=operation1 | |
- name: message 2 | |
debug: msg=operation2 | |
- name: message 3 | |
debug: msg=operation3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stolen from https://medium.com/opsops/using-block-for-handlers-in-ansible-a55f45b62a96 | |
################################################################################ | |
# I wanted to change an Ansible handler task to run a couple of steps. The # | |
# first is conditional but the second is not. I thought I could do this with a # | |
# block but I guess that's not supported but I found the above article that # | |
# presented a way to do it in a different way. # | |
################################################################################ | |
- name: Try technique to run multiple tasks in a handler | |
hosts: localhost | |
gather_facts: no | |
tasks: | |
- command: id | |
notify: restart test | |
- command: id | |
notify: restart test | |
- command: id | |
notify: restart test | |
- command: id | |
notify: restart test | |
handlers: | |
- name: restart test | |
import_tasks: restart_test.yml # this causes "ERROR! The requested handler 'restart test' was not found in either the main handlers list nor in the listening handlers list" | |
# include_tasks: restart_test.yml # this works |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!