From 576593e175fa010dceaa181e4d0e8ac12056af57 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 17 May 2019 12:52:39 -0500 Subject: [PATCH] Whitelist listen as a valid keyword on TaskInclude (#56586) * Whitelist listen as a valid keyword on TaskInclude. Fixes #56580 * Move 'listen' to HandlerTaskInclude * Remove trailing newline --- changelogs/fragments/include_tasks_listen.yml | 3 ++ lib/ansible/playbook/handler_task_include.py | 2 + lib/ansible/playbook/task_include.py | 2 +- .../valid_include_keywords/include_me.yml | 6 +++ .../include_me_listen.yml | 2 + .../include_me_notify.yml | 2 + .../valid_include_keywords/playbook.yml | 39 +++++++++++++++++++ 7 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/include_tasks_listen.yml create mode 100644 test/integration/targets/include_import/valid_include_keywords/include_me.yml create mode 100644 test/integration/targets/include_import/valid_include_keywords/include_me_listen.yml create mode 100644 test/integration/targets/include_import/valid_include_keywords/include_me_notify.yml create mode 100644 test/integration/targets/include_import/valid_include_keywords/playbook.yml diff --git a/changelogs/fragments/include_tasks_listen.yml b/changelogs/fragments/include_tasks_listen.yml new file mode 100644 index 0000000000..0072fff5a9 --- /dev/null +++ b/changelogs/fragments/include_tasks_listen.yml @@ -0,0 +1,3 @@ +bugfixes: +- include_tasks - whitelist ``listen`` as a valid keyword + (https://github.com/ansible/ansible/issues/56580) diff --git a/lib/ansible/playbook/handler_task_include.py b/lib/ansible/playbook/handler_task_include.py index 6fc7de3f44..90290f481b 100644 --- a/lib/ansible/playbook/handler_task_include.py +++ b/lib/ansible/playbook/handler_task_include.py @@ -26,6 +26,8 @@ from ansible.playbook.task_include import TaskInclude class HandlerTaskInclude(Handler, TaskInclude): + VALID_INCLUDE_KEYWORDS = frozenset(('listen',) + tuple(TaskInclude.VALID_INCLUDE_KEYWORDS)) + @staticmethod def load(data, block=None, role=None, task_include=None, variable_manager=None, loader=None): t = HandlerTaskInclude(block=block, role=role, task_include=task_include) diff --git a/lib/ansible/playbook/task_include.py b/lib/ansible/playbook/task_include.py index 4eb705ae2f..365ce30bb6 100644 --- a/lib/ansible/playbook/task_include.py +++ b/lib/ansible/playbook/task_include.py @@ -82,7 +82,7 @@ class TaskInclude(Task): def preprocess_data(self, ds): ds = super(TaskInclude, self).preprocess_data(ds) - diff = set(ds.keys()).difference(TaskInclude.VALID_INCLUDE_KEYWORDS) + diff = set(ds.keys()).difference(self.VALID_INCLUDE_KEYWORDS) for k in diff: # This check doesn't handle ``include`` as we have no idea at this point if it is static or not if ds[k] is not Sentinel and ds['action'] in ('include_tasks', 'include_role'): diff --git a/test/integration/targets/include_import/valid_include_keywords/include_me.yml b/test/integration/targets/include_import/valid_include_keywords/include_me.yml new file mode 100644 index 0000000000..ab5c6a9c96 --- /dev/null +++ b/test/integration/targets/include_import/valid_include_keywords/include_me.yml @@ -0,0 +1,6 @@ +- debug: + msg: include_me +- assert: + that: + - loopy == 1 + - baz == 'qux' diff --git a/test/integration/targets/include_import/valid_include_keywords/include_me_listen.yml b/test/integration/targets/include_import/valid_include_keywords/include_me_listen.yml new file mode 100644 index 0000000000..47b424ada1 --- /dev/null +++ b/test/integration/targets/include_import/valid_include_keywords/include_me_listen.yml @@ -0,0 +1,2 @@ +- debug: + msg: listen diff --git a/test/integration/targets/include_import/valid_include_keywords/include_me_notify.yml b/test/integration/targets/include_import/valid_include_keywords/include_me_notify.yml new file mode 100644 index 0000000000..4501e38047 --- /dev/null +++ b/test/integration/targets/include_import/valid_include_keywords/include_me_notify.yml @@ -0,0 +1,2 @@ +- debug: + msg: notify diff --git a/test/integration/targets/include_import/valid_include_keywords/playbook.yml b/test/integration/targets/include_import/valid_include_keywords/playbook.yml new file mode 100644 index 0000000000..a7ddeb4e92 --- /dev/null +++ b/test/integration/targets/include_import/valid_include_keywords/playbook.yml @@ -0,0 +1,39 @@ +- hosts: localhost + gather_facts: false + handlers: + - include_tasks: include_me_listen.yml + listen: + - include_me_listen + + - name: Include Me Notify + include_tasks: include_me_notify.yml + + tasks: + - name: Include me + include_tasks: include_me.yml + args: + apply: + tags: + - bar + debugger: ~ + ignore_errors: false + loop: + - 1 + loop_control: + loop_var: loopy + no_log: false + register: this_isnt_useful + run_once: true + tags: + - foo + vars: + baz: qux + when: true + + - command: "true" + notify: + - include_me_listen + + - command: "true" + notify: + - Include Me Notify