From 3bda4eae6f1273a42f14b3dedc0d4f5928b290f6 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 29 Nov 2022 16:43:14 +0100 Subject: [PATCH] Fix repr(Task) to check action when testing for a meta task (#79464) Fixes #79459 --- changelogs/fragments/79459-fix-meta-task-check.yml | 2 ++ lib/ansible/playbook/task.py | 2 +- test/integration/targets/tasks/playbook.yml | 12 ++++++++++++ test/integration/targets/tasks/runme.sh | 3 +++ test/integration/targets/tasks/tasks/main.yml | 4 ---- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/79459-fix-meta-task-check.yml create mode 100644 test/integration/targets/tasks/playbook.yml create mode 100755 test/integration/targets/tasks/runme.sh delete mode 100644 test/integration/targets/tasks/tasks/main.yml diff --git a/changelogs/fragments/79459-fix-meta-task-check.yml b/changelogs/fragments/79459-fix-meta-task-check.yml new file mode 100644 index 00000000000..14f39791bfb --- /dev/null +++ b/changelogs/fragments/79459-fix-meta-task-check.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Fix a traceback occuring when a task is named ``meta`` (https://github.com/ansible/ansible/issues/79459)" diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 6a9136d2541..1a71336babd 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -138,7 +138,7 @@ class Task(Base, Conditional, Taggable, CollectionSearch): def __repr__(self): ''' returns a human readable representation of the task ''' - if self.get_name() in C._ACTION_META: + if self.action in C._ACTION_META: return "TASK: meta (%s)" % self.args['_raw_params'] else: return "TASK: %s" % self.get_name() diff --git a/test/integration/targets/tasks/playbook.yml b/test/integration/targets/tasks/playbook.yml new file mode 100644 index 00000000000..04f04217160 --- /dev/null +++ b/test/integration/targets/tasks/playbook.yml @@ -0,0 +1,12 @@ +- hosts: localhost + gather_facts: false + tasks: + # make sure tasks with an undefined variable in the name are gracefully handled + - name: "Task name with undefined variable: {{ not_defined }}" + debug: + msg: Hello + + # ensure we properly test for an action name, not a task name when cheking for a meta task + - name: "meta" + debug: + msg: Hello \ No newline at end of file diff --git a/test/integration/targets/tasks/runme.sh b/test/integration/targets/tasks/runme.sh new file mode 100755 index 00000000000..57cbf28a858 --- /dev/null +++ b/test/integration/targets/tasks/runme.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +ansible-playbook playbook.yml \ No newline at end of file diff --git a/test/integration/targets/tasks/tasks/main.yml b/test/integration/targets/tasks/tasks/main.yml deleted file mode 100644 index f6ac1114d0f..00000000000 --- a/test/integration/targets/tasks/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -# make sure tasks with an undefined variable in the name are gracefully handled -- name: "Task name with undefined variable: {{ not_defined }}" - debug: - msg: Hello