From 464e1b6a5a18f61a770c62b80b31782c7e6947a9 Mon Sep 17 00:00:00 2001 From: Fabio Alessandro Locati Date: Fri, 9 Dec 2016 13:39:40 +0000 Subject: [PATCH] Improve the dependency on univention (aka: declare it and fail nicely if it is not present) (#18840) --- .../modules/univention/udm_dns_record.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/univention/udm_dns_record.py b/lib/ansible/modules/univention/udm_dns_record.py index 92cea504948..120666beded 100644 --- a/lib/ansible/modules/univention/udm_dns_record.py +++ b/lib/ansible/modules/univention/udm_dns_record.py @@ -30,10 +30,16 @@ from ansible.module_utils.univention_umc import ( config, uldap, ) -from univention.admin.handlers.dns import ( - forward_zone, - reverse_zone, -) + +HAVE_UNIVENTION = False +try: + from univention.admin.handlers.dns import ( + forward_zone, + reverse_zone, + ) + HAVE_UNIVENTION = True +except ImportError: + pass ANSIBLE_METADATA = {'status': ['preview'], @@ -51,6 +57,7 @@ description: It uses the python API of the UCS to create a new object or edit it." requirements: - Python >= 2.6 + - Univention options: state: required: false @@ -117,6 +124,10 @@ def main(): ('state', 'present', ['data']) ]) ) + + if not HAVE_UNIVENTION: + module.fail_json(msg="This module requires univention python bindings") + type = module.params['type'] zone = module.params['zone'] name = module.params['name']