Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach with_subelements to apply filters to the inner list. #4

Open
wants to merge 1 commit into
base: updox-2.8.5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ansible/plugins/lookup/subelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
from ansible.utils.listify import listify_lookup_plugin_terms


FLAGS = ('skip_missing',)
FLAGS = ('skip_missing','filter')


class LookupModule(LookupBase):
Expand Down Expand Up @@ -138,6 +138,7 @@ def _raise_terms_error(msg=""):
continue

skip_missing = boolean(flags.get('skip_missing', False), strict=False)
filters = flags.get('filter', False)
subvalue = item0
lastsubkey = False
sublist = []
Expand All @@ -162,6 +163,12 @@ def _raise_terms_error(msg=""):
raise AnsibleError("the key %s should point to a list, got '%s'" % (subkey, subvalue[subkey]))
else:
sublist = subvalue.pop(subkey, [])

if filters:
if isinstance(filters, list):
filters = ' | '.join(filters)
sublist = self._templar.template("{{ %s | %s }}" % (sublist, filters))

for item1 in sublist:
ret.append((item0, item1))

Expand Down