Skip to content
Draft
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
21 changes: 14 additions & 7 deletions plugins/lookup/datahub_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,23 @@ def run(self, terms, variables=None, **kwargs):

all_instance_groups = {ig['name']:ig for ig in datahub['instanceGroups']}
results = []
flattened_terms = LookupBase._flatten(terms)

for term in LookupBase._flatten(terms):
display.vvv("Filtering instance groups for %s[%s]" % (self.get_option('datahub'), term))
if term in all_instance_groups:
if self.get_option('detailed'):
results.append(all_instance_groups[term]['instances'])
if flattened_terms:
for term in flattened_terms:
display.vvv("Filtering instance groups for %s[%s]" % (self.get_option('datahub'), term))
if term in all_instance_groups:
if self.get_option('detailed'):
results.append(all_instance_groups[term]['instances'])
else:
results.append([i['fqdn'] for i in all_instance_groups[term]['instances']])
else:
results.append([i['fqdn'] for i in all_instance_groups[term]['instances']])
results.append(self.get_option('default'))
else:
if self.get_option('detailed'):
results.append([all_instance_groups[group]['instances'] for group in all_instance_groups])
else:
results.append(self.get_option('default'))
results.append([i['fqdn'] for group in all_instance_groups for i in all_instance_groups[group]['instances']])
return results
except KeyError as e:
raise AnsibleError("Error parsing result: %s" % to_native(e))
Expand Down