Skip to content

Commit 3d7b004

Browse files
committed
fix: Inject ldap implicitly to the settings loader
NO_JIRA ``` 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 3d7b004

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
@@ -3,6 +3,7 @@
33
import inspect
44
import os
55
import sys
6+
from contextlib import suppress
67
from pathlib import Path
78
from typing import Any
89
from warnings import warn
@@ -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)