Skip to content

[202503] Fix Ansible module interpreter discovery - #1409

Merged
Lun Yue (lunyue-ms) merged 1 commit into
Azure:202503from
lunyue-ms:fix/202503-ansible-module-shebang
Sep 11, 2026
Merged

Lun Yue (lunyue-ms) merged 1 commit into
Azure:202503from
lunyue-ms:fix/202503-ansible-module-shebang

Conversation

@lunyue-ms

Copy link
Copy Markdown

Description of PR

Backport sonic-net/sonic-mgmt#19258 to update legacy Ansible module shebangs from #!/usr/bin/env python to #!/usr/bin/python.

Recent Elastictest runs for Azure/sonic-buildimage-msft#3073 use ansible-core 2.20.9 and fail during Read duts minigraph because Ansible executes /usr/bin/env python literally, while the current sonic-mgmt container has no python alias. The supported /usr/bin/python shebang allows Ansible interpreter discovery to select the available Python 3 interpreter.

testbed_vm_info.py already had the corrected shebang on this branch, so this backport updates the remaining 23 modules.

Type of change

  • Bug fix
  • Testbed and Framework (new/improvement)
  • New test case
  • Test case improvement

Back port request

  • 202503

Validation

  • Reproduced the Elastictest failure with ansible-core 2.20.9 and an #!/usr/bin/env python custom module.
  • Confirmed that changing the shebang to #!/usr/bin/python enables interpreter discovery and succeeds with the available Python 3 interpreter.
  • Confirmed the PR contains only the upstream shebang changes.

…#19258)

What is the motivation for this PR?
We encountered the following issue when trying to upgrade ansible:
/bin/sh: 1: /usr/bin/env python3: not found
This error occurred when attempting to invoke certain Ansible modules.

According to the Module format and documentation,

image the recommended shebang is: `#!/usr/bin/python`
From the logs, we can observe the following behavior:

When the shebang is /usr/bin/env python, Ansible translates it into:
   203 1751357337.89274: _low_level_execute_command(): starting
   203 1751357337.89277: _low_level_execute_command(): executing: /bin/sh -c ''"'"'/usr/bin/env python'"'"' && sleep 0'
In contrast, when using /usr/bin/python, Ansible attempts a full interpreter discovery:
   171 1751357179.48738: _low_level_execute_command(): starting
   171 1751357179.48741: _low_level_execute_command(): executing: /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'python3.13'"'"'; command -v '"'"'python3.12'"'"'; command -v '"'"'python3.11'"'"'; command -v '"'"'python3.10'"'"'; command -v '"'"'python3.9'"'"'; command -v '"'"'python3.8'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python3'"'"'; echo ENDFOUND && sleep 0'
This indicates that Ansible treats /usr/bin/env python literally and does not invoke its interpreter auto-discovery logic, leading to failures on systems without the python symlink.

To satisfy the requirements of the latest ansible, we update the shebang lines in all affected modules in advance.

How did you do it?
To satisfy the requirements of the latest ansible, this PR updates the shebang lines in all affected modules to #!/usr/bin/python.

How did you verify/test it?
We need to make sure that this change won't affect current test firstly -- test by pipeline itself. And then, we need to make sure that this change works in the new version -- test locally.

(cherry picked from commit b21e61f)
Signed-off-by: Lun Yue <17232861+lunyue-ms@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.

@lunyue-ms
Lun Yue (lunyue-ms) merged commit 188a4a7 into Azure:202503 Sep 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants