From fd5024846337a05dac50079d823ed10d5e2e06c0 Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Fri, 20 Apr 2018 20:44:47 +0530 Subject: [PATCH] nios lookup errors out when there are no results #37970 (#39027) * Update nios.py * Update nios.py * Update nios.py * nios lookup errors out when there are no results #37970 Open Indentation failure issue resolved * Returning empty list instead of None In case of no results, res will be returned as an empty list instead of None (implementing ganeshrn comment) --- lib/ansible/plugins/lookup/nios.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/lookup/nios.py b/lib/ansible/plugins/lookup/nios.py index 87751cd7b42..6a090104c92 100644 --- a/lib/ansible/plugins/lookup/nios.py +++ b/lib/ansible/plugins/lookup/nios.py @@ -108,7 +108,10 @@ class LookupModule(LookupBase): provider = kwargs.pop('provider', {}) wapi = WapiLookup(provider) res = wapi.get_object(obj_type, filter_data, return_fields=return_fields) - for obj in res: - if 'extattrs' in obj: - obj['extattrs'] = flatten_extattrs(obj['extattrs']) + if res is not None: + for obj in res: + if 'extattrs' in obj: + obj['extattrs'] = flatten_extattrs(obj['extattrs']) + else: + res = [] return res