diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index adef9299..f28110fc 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -717,9 +717,9 @@ def switch_organization(self, org_id): def organization_by_name(self, org_name): url = "/api/user/orgs" organizations = self._send_request(url, headers=self.headers, method='GET') - for org in organizations: - if org['name'] == org_name: - return org['orgId'] + orga = next((org for org in organizations if org['name'] == org_name)) + if orga: + return orga['orgId'] return self._module.fail_json(failed=True, msg="Current user isn't member of organization: %s" % org_name)