From a79c57b1e1edf85e026f947d09a96207b86d6d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20R=C3=BCetschi?= Date: Fri, 12 Apr 2019 21:20:36 +0200 Subject: [PATCH] Backport/2.7/55083 (#55141) * The Univention modules have a issue with an unassigned variable. The variable diff is only assigned if state is 'present', else the variable is unused. But the module will return the diff variable as a return value. If the state isn't 'present' the module will fail with an python UnboundLocalError exception. (cherry picked from commit 26fa97922abb9bc197af5745e83c235c2d652116) * Add a changelog fragment for PR 55083. (cherry picked from commit b4ae654890a606bf5321c6b1a612d77de9ef47dd) --- .../fragments/55083-univention-diff-UnboundLocalError.yaml | 6 ++++++ lib/ansible/modules/cloud/univention/udm_dns_record.py | 1 + lib/ansible/modules/cloud/univention/udm_dns_zone.py | 1 + lib/ansible/modules/cloud/univention/udm_group.py | 1 + lib/ansible/modules/cloud/univention/udm_share.py | 1 + lib/ansible/modules/cloud/univention/udm_user.py | 1 + 6 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/55083-univention-diff-UnboundLocalError.yaml diff --git a/changelogs/fragments/55083-univention-diff-UnboundLocalError.yaml b/changelogs/fragments/55083-univention-diff-UnboundLocalError.yaml new file mode 100644 index 00000000000..f7f8cfb86a3 --- /dev/null +++ b/changelogs/fragments/55083-univention-diff-UnboundLocalError.yaml @@ -0,0 +1,6 @@ +bugfixes: + - udm_user - Fix issues when state is absent with undefined variable diff at the module return. + - udm_group - Fix issues when state is absent with undefined variable diff at the module return. + - udm_share - Fix issues when state is absent with undefined variable diff at the module return. + - udm_dns_zone - Fix issues when state is absent with undefined variable diff at the module return. + - udm_dns_record - Fix issues when state is absent with undefined variable diff at the module return. diff --git a/lib/ansible/modules/cloud/univention/udm_dns_record.py b/lib/ansible/modules/cloud/univention/udm_dns_record.py index 5ad7b90b441..cd580a826b2 100644 --- a/lib/ansible/modules/cloud/univention/udm_dns_record.py +++ b/lib/ansible/modules/cloud/univention/udm_dns_record.py @@ -122,6 +122,7 @@ def main(): data = module.params['data'] state = module.params['state'] changed = False + diff = None obj = list(ldap_search( '(&(objectClass=dNSZone)(zoneName={})(relativeDomainName={}))'.format(zone, name), diff --git a/lib/ansible/modules/cloud/univention/udm_dns_zone.py b/lib/ansible/modules/cloud/univention/udm_dns_zone.py index 5b3069f4bdc..03af2fb1f97 100644 --- a/lib/ansible/modules/cloud/univention/udm_dns_zone.py +++ b/lib/ansible/modules/cloud/univention/udm_dns_zone.py @@ -169,6 +169,7 @@ def main(): mx = module.params['mx'] state = module.params['state'] changed = False + diff = None obj = list(ldap_search( '(&(objectClass=dNSZone)(zoneName={}))'.format(zone), diff --git a/lib/ansible/modules/cloud/univention/udm_group.py b/lib/ansible/modules/cloud/univention/udm_group.py index 7e6564591e5..55064b9bed4 100644 --- a/lib/ansible/modules/cloud/univention/udm_group.py +++ b/lib/ansible/modules/cloud/univention/udm_group.py @@ -111,6 +111,7 @@ def main(): subpath = module.params['subpath'] state = module.params['state'] changed = False + diff = None groups = list(ldap_search( '(&(objectClass=posixGroup)(cn={}))'.format(name), diff --git a/lib/ansible/modules/cloud/univention/udm_share.py b/lib/ansible/modules/cloud/univention/udm_share.py index a90e8382328..4523baec0b9 100644 --- a/lib/ansible/modules/cloud/univention/udm_share.py +++ b/lib/ansible/modules/cloud/univention/udm_share.py @@ -476,6 +476,7 @@ def main(): name = module.params['name'] state = module.params['state'] changed = False + diff = None obj = list(ldap_search( '(&(objectClass=univentionShare)(cn={}))'.format(name), diff --git a/lib/ansible/modules/cloud/univention/udm_user.py b/lib/ansible/modules/cloud/univention/udm_user.py index 0cb77c289bf..9d3ff6b76af 100644 --- a/lib/ansible/modules/cloud/univention/udm_user.py +++ b/lib/ansible/modules/cloud/univention/udm_user.py @@ -410,6 +410,7 @@ def main(): subpath = module.params['subpath'] state = module.params['state'] changed = False + diff = None users = list(ldap_search( '(&(objectClass=posixAccount)(uid={}))'.format(username),