From 3d7b0040a6111e657fb4ed5e1e8f50f4266f05a3 Mon Sep 17 00:00:00 2001 From: Bruno Rocha Date: Fri, 9 May 2025 17:46:42 +0100 Subject: [PATCH] fix: Inject ldap implicitly to the settings loader NO_JIRA ``` File "/etc/tower/conf.d/ldap.py", line 2, in ldap.OPT_X_TLS_REQUIRE_CERT: True, ^^^^ NameError: name 'ldap' is not defined ``` --- ansible_base/lib/dynamic_config/dynaconf_helpers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ansible_base/lib/dynamic_config/dynaconf_helpers.py b/ansible_base/lib/dynamic_config/dynaconf_helpers.py index a3eb7d378..e248edfa5 100644 --- a/ansible_base/lib/dynamic_config/dynaconf_helpers.py +++ b/ansible_base/lib/dynamic_config/dynaconf_helpers.py @@ -3,6 +3,7 @@ import inspect import os import sys +from contextlib import suppress from pathlib import Path from typing import Any from warnings import warn @@ -269,6 +270,13 @@ def load_python_file_with_injected_context(*paths: str, settings: Dynaconf, run_ files_to_load = glob(pattern) for file_path in files_to_load: scope = settings.as_dict() + + # Inject ldap module because some legacy custom config expect it on the global scope + with suppress(ImportError): # ldap may not be installed on all environments + import ldap + + scope["ldap"] = ldap + file_path = os.path.abspath(file_path) with open(file_path, "rb") as to_compile: code = compile(to_compile.read(), file_path, "exec")