diff --git a/changelogs/fragments/41240-fix-os_quota-without-cinder.yaml b/changelogs/fragments/41240-fix-os_quota-without-cinder.yaml new file mode 100644 index 00000000000..405ef23730b --- /dev/null +++ b/changelogs/fragments/41240-fix-os_quota-without-cinder.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "os_quota - fix failure to set compute or network quota when volume service is not available" diff --git a/lib/ansible/modules/cloud/openstack/os_quota.py b/lib/ansible/modules/cloud/openstack/os_quota.py index 2486ab1de48..13cde37d841 100644 --- a/lib/ansible/modules/cloud/openstack/os_quota.py +++ b/lib/ansible/modules/cloud/openstack/os_quota.py @@ -107,6 +107,7 @@ options: requirements: - "python >= 2.7" - "openstacksdk >= 0.13.0" + - "keystoneauth1 >= 3.4.0" ''' EXAMPLES = ''' @@ -225,7 +226,17 @@ openstack_quotas: ''' -from ansible.module_utils.basic import AnsibleModule +import traceback + +KEYSTONEAUTH1_IMP_ERR = None +try: + from keystoneauth1 import exceptions as ksa_exceptions + HAS_KEYSTONEAUTH1 = True +except ImportError: + KEYSTONEAUTH1_IMP_ERR = traceback.format_exc() + HAS_KEYSTONEAUTH1 = False + +from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module @@ -249,12 +260,12 @@ def _get_quotas(sdk, module, cloud, project): quota = {} try: quota['volume'] = _get_volume_quotas(cloud, project) - except sdk.exceptions.NotFoundException: + except ksa_exceptions.EndpointNotFound: module.warn("No public endpoint for volumev2 service was found. Ignoring volume quotas.") try: quota['network'] = _get_network_quotas(cloud, project) - except sdk.exceptions.NotFoundException: + except ksa_exceptions.EndpointNotFound: module.warn("No public endpoint for network service was found. Ignoring network quotas.") quota['compute'] = _get_compute_quotas(cloud, project) @@ -364,6 +375,9 @@ def main(): supports_check_mode=True ) + if not HAS_KEYSTONEAUTH1: + module.fail_json(msg=missing_required_lib("keystoneauth1"), exception=KEYSTONEAUTH1_IMP_ERR) + sdk, cloud = openstack_cloud_from_module(module) try: cloud_params = dict(module.params)