summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/handlers
diff options
context:
space:
mode:
authorSloane Hertel <19572925+s-hertel@users.noreply.github.com>2021-08-03 21:16:19 +0200
committerGitHub <noreply@github.com>2021-08-03 21:16:19 +0200
commitc8d413164d2a7f76376792bb0028000909ac68b7 (patch)
tree3b1b39503f0af918eb60cc6046ffddcedb8f22ae /test/integration/targets/handlers
parentansible-test - add ssh debugging logging (#75374) (diff)
downloadansible-c8d413164d2a7f76376792bb0028000909ac68b7.tar.xz
ansible-c8d413164d2a7f76376792bb0028000909ac68b7.zip
ignore/warn for undefined vars in unused handler names (#75244)
* Make undefined variables in handler names non-fatal if the handler is not used * If the handler has no way to be notified (i.e. the name can't be templated and the handler has no listen topics), display a warning * Add tests for variables in handler names * changelog
Diffstat (limited to 'test/integration/targets/handlers')
-rw-r--r--test/integration/targets/handlers/58841.yml9
-rw-r--r--test/integration/targets/handlers/roles/import_template_handler_names/tasks/main.yml11
-rw-r--r--test/integration/targets/handlers/roles/template_handler_names/handlers/main.yml5
-rw-r--r--test/integration/targets/handlers/roles/template_handler_names/tasks/evaluation_time.yml5
-rw-r--r--test/integration/targets/handlers/roles/template_handler_names/tasks/lazy_evaluation.yml5
-rwxr-xr-xtest/integration/targets/handlers/runme.sh18
6 files changed, 53 insertions, 0 deletions
diff --git a/test/integration/targets/handlers/58841.yml b/test/integration/targets/handlers/58841.yml
new file mode 100644
index 0000000000..eea5c2f3c3
--- /dev/null
+++ b/test/integration/targets/handlers/58841.yml
@@ -0,0 +1,9 @@
+---
+- hosts: localhost
+ gather_facts: no
+ tasks:
+ - include_role:
+ name: import_template_handler_names
+ tags:
+ - lazy_evaluation
+ - evaluation_time
diff --git a/test/integration/targets/handlers/roles/import_template_handler_names/tasks/main.yml b/test/integration/targets/handlers/roles/import_template_handler_names/tasks/main.yml
new file mode 100644
index 0000000000..3bc285e52a
--- /dev/null
+++ b/test/integration/targets/handlers/roles/import_template_handler_names/tasks/main.yml
@@ -0,0 +1,11 @@
+- import_role:
+ name: template_handler_names
+ tasks_from: lazy_evaluation
+ tags:
+ - lazy_evaluation
+
+- import_role:
+ name: template_handler_names
+ tasks_from: evaluation_time
+ tags:
+ - evaluation_time
diff --git a/test/integration/targets/handlers/roles/template_handler_names/handlers/main.yml b/test/integration/targets/handlers/roles/template_handler_names/handlers/main.yml
new file mode 100644
index 0000000000..bf8ca85140
--- /dev/null
+++ b/test/integration/targets/handlers/roles/template_handler_names/handlers/main.yml
@@ -0,0 +1,5 @@
+- name: handler name with {{ test_var }}
+ debug: msg='handler with var ran'
+
+- name: handler name
+ debug: msg='handler ran'
diff --git a/test/integration/targets/handlers/roles/template_handler_names/tasks/evaluation_time.yml b/test/integration/targets/handlers/roles/template_handler_names/tasks/evaluation_time.yml
new file mode 100644
index 0000000000..c0706fc50e
--- /dev/null
+++ b/test/integration/targets/handlers/roles/template_handler_names/tasks/evaluation_time.yml
@@ -0,0 +1,5 @@
+- debug: msg='notify handler with variable in name'
+ notify: handler name with myvar
+ changed_when: True
+ tags:
+ - evaluation_time
diff --git a/test/integration/targets/handlers/roles/template_handler_names/tasks/lazy_evaluation.yml b/test/integration/targets/handlers/roles/template_handler_names/tasks/lazy_evaluation.yml
new file mode 100644
index 0000000000..e82dca06e3
--- /dev/null
+++ b/test/integration/targets/handlers/roles/template_handler_names/tasks/lazy_evaluation.yml
@@ -0,0 +1,5 @@
+- debug: msg='notify handler'
+ notify: handler name
+ changed_when: True
+ tags:
+ - lazy_evaluation
diff --git a/test/integration/targets/handlers/runme.sh b/test/integration/targets/handlers/runme.sh
index 17255de194..7c403b4ea2 100755
--- a/test/integration/targets/handlers/runme.sh
+++ b/test/integration/targets/handlers/runme.sh
@@ -96,3 +96,21 @@ result="$(ansible-playbook test_handlers_template_run_once.yml -i inventory.hand
set -e
grep -q "handler A" <<< "$result"
grep -q "handler B" <<< "$result"
+
+# Test an undefined variable in another handler name isn't a failure
+ansible-playbook 58841.yml "$@" --tags lazy_evaluation 2>&1 | tee out.txt ; cat out.txt
+grep out.txt -e "\[WARNING\]: Handler 'handler name with {{ test_var }}' is unusable"
+[ "$(grep out.txt -ce 'handler ran')" = "1" ]
+[ "$(grep out.txt -ce 'handler with var ran')" = "0" ]
+
+# Test templating a handler name with a defined variable
+ansible-playbook 58841.yml "$@" --tags evaluation_time -e test_var=myvar | tee out.txt ; cat out.txt
+[ "$(grep out.txt -ce 'handler ran')" = "0" ]
+[ "$(grep out.txt -ce 'handler with var ran')" = "1" ]
+
+# Test the handler is not found when the variable is undefined
+ansible-playbook 58841.yml "$@" --tags evaluation_time 2>&1 | tee out.txt ; cat out.txt
+grep out.txt -e "ERROR! The requested handler 'handler name with myvar' was not found"
+grep out.txt -e "\[WARNING\]: Handler 'handler name with {{ test_var }}' is unusable"
+[ "$(grep out.txt -ce 'handler ran')" = "0" ]
+[ "$(grep out.txt -ce 'handler with var ran')" = "0" ]