vultr: Make get_result handle list (#42890)

Currently get_result() can only handle a dict. When requiring facts, and
when there is more than one fact, get_result() should be able to handle
a list of dicts, so the normalization process happens to all the items.
pull/42615/head
Yanis Guenane 6 years ago committed by René Moser
parent b6e9df2065
commit 577427b1c2

@ -225,8 +225,7 @@ class Vultr:
self.module.fail_json(msg="Could not find %s with %s: %s" % (resource, key, value))
def get_result(self, resource):
if resource:
def normalize_result(self, resource):
for search_key, config in self.returns.items():
if search_key in resource:
if 'convert_to' in config:
@ -238,7 +237,15 @@ class Vultr:
resource[search_key] = True if resource[search_key] == 'yes' else False
if 'key' in config:
self.result[self.namespace][config['key']] = resource[search_key]
resource[config['key']] = resource[search_key]
return resource
def get_result(self, resource):
if resource:
if isinstance(resource, list):
self.result[self.namespace] = [self.normalize_result(item) for item in resource]
else:
self.result[self.namespace][search_key] = resource[search_key]
self.result[self.namespace] = self.normalize_result(resource)
return self.result

Loading…
Cancel
Save