diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 5b67c745c4..752defec2b 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -274,12 +274,13 @@ class AnsibleCloudStack: return None args = {} - args['name'] = domain args['listall'] = True domains = self.cs.listDomains(**args) if domains: - self.domain = domains['domain'][0] - return self._get_by_key(key, self.domain) + for d in domains['domain']: + if d['path'].lower() in [ domain.lower(), "root/" + domain.lower(), "root" + domain.lower() ]: + self.domain = d + return self._get_by_key(key, self.domain) self.module.fail_json(msg="Domain '%s' not found" % domain) diff --git a/v1/ansible/module_utils/cloudstack.py b/v1/ansible/module_utils/cloudstack.py index 5b67c745c4..752defec2b 100644 --- a/v1/ansible/module_utils/cloudstack.py +++ b/v1/ansible/module_utils/cloudstack.py @@ -274,12 +274,13 @@ class AnsibleCloudStack: return None args = {} - args['name'] = domain args['listall'] = True domains = self.cs.listDomains(**args) if domains: - self.domain = domains['domain'][0] - return self._get_by_key(key, self.domain) + for d in domains['domain']: + if d['path'].lower() in [ domain.lower(), "root/" + domain.lower(), "root" + domain.lower() ]: + self.domain = d + return self._get_by_key(key, self.domain) self.module.fail_json(msg="Domain '%s' not found" % domain)