From 74c14c67439ff2d5e24dfb142c7fadf701fb6712 Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Mon, 3 Aug 2020 10:30:45 -0500 Subject: [PATCH] Strip spaces in module names in explicit actions (#71040) * Strip spaces in module names in explicit actions Change: - When an action is called like "action: copy foo=bar", strip spaces around the action name. - This allows "action: copy foo=bar" to work as expected. Test Plan: - New integration tests Tickets: - Fixes #62136 Signed-off-by: Rick Elrod --- .../62136_strip_spaces_from_action_names.yml | 2 ++ lib/ansible/parsing/mod_args.py | 4 ++-- .../parsing/roles/test_good_parsing/tasks/main.yml | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/62136_strip_spaces_from_action_names.yml diff --git a/changelogs/fragments/62136_strip_spaces_from_action_names.yml b/changelogs/fragments/62136_strip_spaces_from_action_names.yml new file mode 100644 index 00000000000..f3ecf642822 --- /dev/null +++ b/changelogs/fragments/62136_strip_spaces_from_action_names.yml @@ -0,0 +1,2 @@ +bugfixes: + - "task parsing - strip spaces from action name when using ``action: foo bar=baz`` form. (https://github.com/ansible/ansible/issues/62136)" diff --git a/lib/ansible/parsing/mod_args.py b/lib/ansible/parsing/mod_args.py index a6906b909c7..b81e81b0721 100644 --- a/lib/ansible/parsing/mod_args.py +++ b/lib/ansible/parsing/mod_args.py @@ -131,9 +131,9 @@ class ModuleArgsParser: tokens = split_args(module_string) if len(tokens) > 1: - return (tokens[0], " ".join(tokens[1:])) + return (tokens[0].strip(), " ".join(tokens[1:])) else: - return (tokens[0], "") + return (tokens[0].strip(), "") def _normalize_parameters(self, thing, action=None, additional_args=None): ''' diff --git a/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml b/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml index 0fb1337e86a..d225c0f9f90 100644 --- a/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml +++ b/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml @@ -202,3 +202,16 @@ - should_not_omit_1 is defined - should_not_omit_2 is defined - should_not_omit_3 == "__omit_place_holder__afb6b9bc3d20bfeaa00a1b23a5930f89" + +- name: Ensure module names are stripped of extra spaces (local_action) + local_action: set_fact b="b" + register: la_set_fact_b + +- name: Ensure module names are stripped of extra spaces (action) + action: set_fact c="c" + register: la_set_fact_c + +- assert: + that: + - b == "b" + - c == "c"