From ba3515bc30f20b72acf3d102de14421b5808a350 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Tue, 22 Mar 2016 11:25:57 +0000 Subject: [PATCH] Allow passing domain name on os_project --- .../modules/extras/cloud/openstack/os_project.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/ansible/modules/extras/cloud/openstack/os_project.py b/lib/ansible/modules/extras/cloud/openstack/os_project.py index b900d42f16..630b26c411 100644 --- a/lib/ansible/modules/extras/cloud/openstack/os_project.py +++ b/lib/ansible/modules/extras/cloud/openstack/os_project.py @@ -161,6 +161,22 @@ def main(): state = module.params['state'] try: + if domain: + opcloud = shade.operator_cloud(**module.params) + try: + # We assume admin is passing domain id + dom = opcloud.get_domain(domain)['id'] + domain = dom + except: + # If we fail, maybe admin is passing a domain name. + # Note that domains have unique names, just like id. + try: + dom = opcloud.search_domains(filters={'name': domain})[0]['id'] + domain = dom + except: + # Ok, let's hope the user is non-admin and passing a sane id + pass + cloud = shade.openstack_cloud(**module.params) project = cloud.get_project(name)