Skip to content

Commit fd3c2dc

Browse files
committed
fix: Inject ldap implicitly to the settings loader
``` File "/etc/tower/conf.d/ldap.py", line 2, in <module> ldap.OPT_X_TLS_REQUIRE_CERT: True, ^^^^ NameError: name 'ldap' is not defined ```
1 parent a46ebe5 commit fd3c2dc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ansible_base/lib/dynamic_config/dynaconf_helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any
88
from warnings import warn
99

10+
from contextlib import suppress
1011
from django.core.exceptions import ImproperlyConfigured
1112
from dynaconf import Dynaconf, Validator
1213
from dynaconf.constants import YAML_EXTENSIONS
@@ -269,6 +270,13 @@ def load_python_file_with_injected_context(*paths: str, settings: Dynaconf, run_
269270
files_to_load = glob(pattern)
270271
for file_path in files_to_load:
271272
scope = settings.as_dict()
273+
274+
# Inject ldap module because some legacy custom config expect it on the global scope
275+
with suppress(ImportError): # ldap may not be installed on all environments
276+
import ldap
277+
278+
scope["ldap"] = ldap
279+
272280
file_path = os.path.abspath(file_path)
273281
with open(file_path, "rb") as to_compile:
274282
code = compile(to_compile.read(), file_path, "exec")

0 commit comments

Comments
 (0)