diff --git a/changelogs/fragments/omit-list-of-dicts.yaml b/changelogs/fragments/omit-list-of-dicts.yaml new file mode 100644 index 00000000000..f6af2f03501 --- /dev/null +++ b/changelogs/fragments/omit-list-of-dicts.yaml @@ -0,0 +1,2 @@ +bugfixes: +- omit - support list types containing dicts (https://github.com/ansible/ansible/issues/45907) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 5cf62538eb8..3b7a4b4d4d1 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -42,13 +42,18 @@ def remove_omit(task_args, omit_token): Remove args with a value equal to the ``omit_token`` recursively to align with now having suboptions in the argument_spec ''' - new_args = {} + if not isinstance(task_args, dict): + return task_args + + new_args = {} for i in iteritems(task_args): if i[1] == omit_token: continue elif isinstance(i[1], dict): new_args[i[0]] = remove_omit(i[1], omit_token) + elif isinstance(i[1], list): + new_args[i[0]] = [remove_omit(v, omit_token) for v in i[1]] else: new_args[i[0]] = i[1] diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py index fab9845f5d9..a02e9f0a41d 100644 --- a/test/units/executor/test_task_executor.py +++ b/test/units/executor/test_task_executor.py @@ -502,6 +502,14 @@ class TestTaskExecutor(unittest.TestCase): 'a_list': ['POPCORN'], }, 'a_list': ['POPCORN'], + 'list_of_lists': [ + ['some', 'thing'], + ], + 'list_of_dicts': [ + { + 'remove': 'POPCORN', + } + ], } expected = { @@ -516,6 +524,10 @@ class TestTaskExecutor(unittest.TestCase): 'a_list': ['POPCORN'], }, 'a_list': ['POPCORN'], + 'list_of_lists': [ + ['some', 'thing'], + ], + 'list_of_dicts': [{}], } self.assertEqual(remove_omit(data, omit_token), expected)