summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSloane Hertel <shertel@redhat.com>2020-11-06 11:46:58 -0500
committerGitHub <noreply@github.com>2020-11-06 11:46:58 -0500
commit0ed7bfc694e5e2efe49fa0e1c8fea0a392c78c04 (patch)
tree3059082dddd4262f0abf69456d15394dcf964d1d
parentc8590c7482dcfc40f7054f629b7b6179f9e38daf (diff)
downloadansible-0ed7bfc694e5e2efe49fa0e1c8fea0a392c78c04.tar.gz
Fix task get_name to always prepend the role name (#72511)
* Fix 'role_name : tast_name' notation if task contains role name * Add tests for notifying handler names which contain the role name Co-authored-by: Thomas Wouters <thomaswouters@gmail.com>
-rw-r--r--changelogs/fragments/72511-always-prepend-role-to-task-name.yml3
-rw-r--r--lib/ansible/playbook/task.py2
-rw-r--r--lib/ansible/plugins/strategy/__init__.py3
-rw-r--r--test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/common_handlers/handlers/main.yml21
-rw-r--r--test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/test_fqcn_handlers/tasks/main.yml11
5 files changed, 35 insertions, 5 deletions
diff --git a/changelogs/fragments/72511-always-prepend-role-to-task-name.yml b/changelogs/fragments/72511-always-prepend-role-to-task-name.yml
new file mode 100644
index 0000000000..8ef70fa946
--- /dev/null
+++ b/changelogs/fragments/72511-always-prepend-role-to-task-name.yml
@@ -0,0 +1,3 @@
+bugfixes:
+ - 'Fix notifying handlers via `role_name : handler_name` when handler name contains the role name. (https://github.com/ansible/ansible/issues/70582)'
+ - 'Fix --list-tasks format `role_name : task_name` when task name contains the role name. (https://github.com/ansible/ansible/issues/72505)'
diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py
index f488d59e09..c49ffb14d5 100644
--- a/lib/ansible/playbook/task.py
+++ b/lib/ansible/playbook/task.py
@@ -122,7 +122,7 @@ class Task(Base, Conditional, Taggable, CollectionSearch):
if self._role:
role_name = self._role.get_name(include_role_fqcn=include_role_fqcn)
- if self._role and self.name and role_name not in self.name:
+ if self._role and self.name:
return "%s : %s" % (role_name, self.name)
elif self.name:
return self.name
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index 278825dd15..025691c936 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -1010,10 +1010,7 @@ class StrategyBase:
notified_hosts += failed_hosts
if len(notified_hosts) > 0:
- saved_name = handler.name
- handler.name = handler_name
self._tqm.send_callback('v2_playbook_on_handler_task_start', handler)
- handler.name = saved_name
bypass_host_loop = False
try:
diff --git a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/common_handlers/handlers/main.yml b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/common_handlers/handlers/main.yml
index d9f732317e..186368f5e6 100644
--- a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/common_handlers/handlers/main.yml
+++ b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/common_handlers/handlers/main.yml
@@ -4,3 +4,24 @@
set_fact:
handler_counter: '{{ handler_counter|int + 1 }}'
failed_when: handler_counter|int > 1
+
+# The following handler contains the role name and should be callable as:
+# 'common_handlers test_fqcn_handler'
+# 'common_handlers : common_handlers test_fqcn_handler`
+# 'testns.testcoll.common_handlers : common_handlers test_fqcn_handler'
+- name: common_handlers test_fqcn_handler
+ set_fact:
+ handler_counter: '{{ handler_counter|int + 1}}'
+ failed_when: handler_counter|int > 2
+
+# The following handler starts with 'role name : ' and should _not_ be listed as:
+# 'common_handlers : common_handlers : test_fqcn_handler`
+# 'testns.testcoll.common_handlers : common_handlers : test_fqcn_handler'
+- name: 'common_handlers : test_fqcn_handler'
+ meta: noop
+
+# The following handler starts with 'fqcn : ' and should _not_ be listed as:
+# 'common_handlers : testns.testcoll.common_handlers : test_fqcn_handler`
+# 'testns.testcoll.common_handlers : testns.testcoll.common_handlers : test_fqcn_handler'
+- name: 'testns.testcoll.common_handlers : test_fqcn_handler'
+ meta: noop
diff --git a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/test_fqcn_handlers/tasks/main.yml b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/test_fqcn_handlers/tasks/main.yml
index db8767d217..6eadb7c2af 100644
--- a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/test_fqcn_handlers/tasks/main.yml
+++ b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/roles/test_fqcn_handlers/tasks/main.yml
@@ -1,7 +1,16 @@
-- debug:
+- name: Fire fqcn handler 1
+ debug:
msg: Fire fqcn handler
changed_when: true
notify:
- 'testns.testcoll.common_handlers : test_fqcn_handler'
- 'common_handlers : test_fqcn_handler'
- 'test_fqcn_handler'
+
+- debug:
+ msg: Fire fqcn handler with role name
+ changed_when: true
+ notify:
+ - 'testns.testcoll.common_handlers : common_handlers test_fqcn_handler'
+ - 'common_handlers : common_handlers test_fqcn_handler'
+ - 'common_handlers test_fqcn_handler'