From 0ce49e22d176a5fccdcd0b5e98e6ecaffc44a048 Mon Sep 17 00:00:00 2001 From: John Sirmon Date: Fri, 6 Mar 2026 19:16:17 -0500 Subject: [PATCH] fix: prefer platform-python over python3 to match waagent interpreter on RHEL 8 On RHEL 8, /usr/libexec/platform-python is the interpreter used by waagent and has the required modules installed. The previous logic selected python3 first, which may lack those modules, causing agent.py to fail with import errors. Moving platform-python to the top of the check order ensures AMA uses the same interpreter as waagent. Fixes #2117 --- AzureMonitorAgent/shim.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AzureMonitorAgent/shim.sh b/AzureMonitorAgent/shim.sh index 5e146f6af..962303567 100644 --- a/AzureMonitorAgent/shim.sh +++ b/AzureMonitorAgent/shim.sh @@ -10,16 +10,16 @@ ARG="$@" function find_python() { local python_exec_command=$1 - - if command -v python3 >/dev/null 2>&1 ; then + if command -v /usr/libexec/platform-python >/dev/null 2>&1 ; then + # Prefer platform-python when available — this is the python waagent uses (RHEL 8+) + # and ensures AMA uses the same interpreter with the same installed modules. + eval ${python_exec_command}="/usr/libexec/platform-python" + elif command -v python3 >/dev/null 2>&1 ; then eval ${python_exec_command}="python3" elif command -v python2 >/dev/null 2>&1 ; then eval ${python_exec_command}="python2" - elif command -v /usr/libexec/platform-python >/dev/null 2>&1 ; then - # If a user-installed python isn't available, check for a platform-python. This is typically only used in RHEL 8.0. - echo "User-installed python not found. Using /usr/libexec/platform-python as the python interpreter." - eval ${python_exec_command}="/usr/libexec/platform-python" fi + } find_python PYTHON