Skip to content

Instantly share code, notes, and snippets.

@pfuntner
Last active April 20, 2021 14:55
Show Gist options
  • Save pfuntner/526b7c397a714f3f4dd774bcbfc6c2e6 to your computer and use it in GitHub Desktop.
Save pfuntner/526b7c397a714f3f4dd774bcbfc6c2e6 to your computer and use it in GitHub Desktop.
Running multiple tasks in an Ansible handler
- block:
- name: message 1
debug: msg=operation1
- name: message 2
debug: msg=operation2
- name: message 3
debug: msg=operation3
# 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
@deadalnix
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment