mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
17b3171917
commit
0d068f1e3a
3 changed files with 20 additions and 1 deletions
2
changelogs/fragments/omit-list-of-dicts.yaml
Normal file
2
changelogs/fragments/omit-list-of-dicts.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- omit - support list types containing dicts (https://github.com/ansible/ansible/issues/45907)
|
|
@ -42,13 +42,18 @@ def remove_omit(task_args, omit_token):
|
||||||
Remove args with a value equal to the ``omit_token`` recursively
|
Remove args with a value equal to the ``omit_token`` recursively
|
||||||
to align with now having suboptions in the argument_spec
|
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):
|
for i in iteritems(task_args):
|
||||||
if i[1] == omit_token:
|
if i[1] == omit_token:
|
||||||
continue
|
continue
|
||||||
elif isinstance(i[1], dict):
|
elif isinstance(i[1], dict):
|
||||||
new_args[i[0]] = remove_omit(i[1], omit_token)
|
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:
|
else:
|
||||||
new_args[i[0]] = i[1]
|
new_args[i[0]] = i[1]
|
||||||
|
|
||||||
|
|
|
@ -502,6 +502,14 @@ class TestTaskExecutor(unittest.TestCase):
|
||||||
'a_list': ['POPCORN'],
|
'a_list': ['POPCORN'],
|
||||||
},
|
},
|
||||||
'a_list': ['POPCORN'],
|
'a_list': ['POPCORN'],
|
||||||
|
'list_of_lists': [
|
||||||
|
['some', 'thing'],
|
||||||
|
],
|
||||||
|
'list_of_dicts': [
|
||||||
|
{
|
||||||
|
'remove': 'POPCORN',
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
|
@ -516,6 +524,10 @@ class TestTaskExecutor(unittest.TestCase):
|
||||||
'a_list': ['POPCORN'],
|
'a_list': ['POPCORN'],
|
||||||
},
|
},
|
||||||
'a_list': ['POPCORN'],
|
'a_list': ['POPCORN'],
|
||||||
|
'list_of_lists': [
|
||||||
|
['some', 'thing'],
|
||||||
|
],
|
||||||
|
'list_of_dicts': [{}],
|
||||||
}
|
}
|
||||||
|
|
||||||
self.assertEqual(remove_omit(data, omit_token), expected)
|
self.assertEqual(remove_omit(data, omit_token), expected)
|
||||||
|
|
Loading…
Reference in a new issue