From 1b5288b7034c23843a20d7bfc5e2dc2c246f4856 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Mon, 4 Apr 2016 13:20:00 +0000 Subject: [PATCH] Only check default_project on resource creation The default_project is checked at the beginning of the module. This raises an exception if the project passed does not exist. This logic only makes sense on resource creation, if a user puts state=absent the module fails, even though the default project is not relevant --- lib/ansible/modules/cloud/openstack/os_user.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_user.py b/lib/ansible/modules/cloud/openstack/os_user.py index d40372990c5..1e148e3d946 100644 --- a/lib/ansible/modules/cloud/openstack/os_user.py +++ b/lib/ansible/modules/cloud/openstack/os_user.py @@ -169,13 +169,6 @@ def main(): cloud = shade.openstack_cloud(**module.params) user = cloud.get_user(name) - project_id = None - if default_project: - project = cloud.get_project(default_project) - if not project: - module.fail_json(msg='Default project %s is not valid' % default_project) - project_id = project['id'] - if domain: opcloud = shade.operator_cloud(**module.params) try: @@ -193,6 +186,13 @@ def main(): pass if state == 'present': + project_id = None + if default_project: + project = cloud.get_project(default_project) + if not project: + module.fail_json(msg='Default project %s is not valid' % default_project) + project_id = project['id'] + if user is None: user = cloud.create_user( name=name, password=password, email=email,