forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix notifying handlers by using an exact match (ansible#55624)
* Fix notifying handlers by using an exact match rather than a string subset if listen is text rather than a list * Enforce better type checking for listeners * Share code for validating handler listeners * Add test for handlers without names * Add test for templating in handlers * Add test for include_role * Add a couple notes about 'listen' for handlers * changelog * Add a test for handlers without names * Test templating in handlers * changelog * Add some tests for include_role * Add a couple notes about 'listen' for handlers * make more sense * move local function into a class method
- Loading branch information
Showing
11 changed files
with
153 additions
and
52 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/55575_notify_handlers_by_exact_match_only.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bugfixes: | ||
- handlers - Only notify a handler if the handler is an exact match by ensuring `listen` is a list of strings. | ||
(https://github.com/ansible/ansible/issues/55575) |
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
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
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
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
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
15 changes: 15 additions & 0 deletions
15
test/integration/targets/handlers/roles/test_templating_in_handlers/handlers/main.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
- name: name1 | ||
set_fact: | ||
role_non_templated_name: True | ||
- name: "{{ handler2 }}" | ||
set_fact: | ||
role_templated_name: True | ||
- name: testlistener1 | ||
set_fact: | ||
role_non_templated_listener: True | ||
listen: name3 | ||
- name: testlistener2 | ||
set_fact: | ||
role_templated_listener: True | ||
listen: "{{ handler4 }}" |
16 changes: 16 additions & 0 deletions
16
test/integration/targets/handlers/roles/test_templating_in_handlers/tasks/main.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
- command: echo Hello World | ||
notify: | ||
- "{{ handler1 }}" | ||
- "{{ handler2 }}" | ||
- "{{ handler3 }}" | ||
- "{{ handler4 }}" | ||
|
||
- meta: flush_handlers | ||
|
||
- assert: | ||
that: | ||
- role_non_templated_name is defined | ||
- role_templated_name is defined | ||
- role_non_templated_listener is defined | ||
- role_templated_listener is undefined |
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
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
43 changes: 43 additions & 0 deletions
43
test/integration/targets/handlers/test_templating_in_handlers.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
- name: test templated values in handlers | ||
hosts: localhost | ||
gather_facts: no | ||
vars: | ||
handler1: name1 | ||
handler2: name2 | ||
handler3: name3 | ||
handler4: name4 | ||
|
||
handlers: | ||
- name: name1 | ||
set_fact: | ||
non_templated_name: True | ||
- name: "{{ handler2 }}" | ||
set_fact: | ||
templated_name: True | ||
- name: testlistener1 | ||
set_fact: | ||
non_templated_listener: True | ||
listen: name3 | ||
- name: testlistener2 | ||
set_fact: | ||
templated_listener: True | ||
listen: "{{ handler4 }}" | ||
|
||
tasks: | ||
- command: echo Hello World | ||
notify: | ||
- "{{ handler1 }}" | ||
- "{{ handler2 }}" | ||
- "{{ handler3 }}" | ||
- "{{ handler4 }}" | ||
|
||
- meta: flush_handlers | ||
|
||
- assert: | ||
that: | ||
- non_templated_name is defined | ||
- templated_name is defined | ||
- non_templated_listener is defined | ||
- templated_listener is undefined | ||
|
||
- include_role: name=test_templating_in_handlers |