Skip to content

Fix shebang to /usr/bin/python in ansible modules for compatibility#19258

Merged
wangxin merged 1 commit intosonic-net:masterfrom
yutongzhang-microsoft:yutonghznag/change_shebang
Jul 2, 2025
Merged

Fix shebang to /usr/bin/python in ansible modules for compatibility#19258
wangxin merged 1 commit intosonic-net:masterfrom
yutongzhang-microsoft:yutonghznag/change_shebang

Conversation

@yutongzhang-microsoft
Copy link
Contributor

@yutongzhang-microsoft yutongzhang-microsoft commented Jun 30, 2025

Description of 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.

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505

Approach

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.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@yutongzhang-microsoft yutongzhang-microsoft changed the title Change shebang in some ansible modules Fix shebang to /usr/bin/python in ansible modules for compatibility Jun 30, 2025
@wangxin
Copy link
Collaborator

wangxin commented Jun 30, 2025

Can you elaborate more about this change? Like why it works now. Why need to make this change?

@wangxin wangxin merged commit b21e61f into sonic-net:master Jul 2, 2025
18 checks passed
@wangxin
Copy link
Collaborator

wangxin commented Jul 2, 2025

Same sonic-mgmt docker is used for all branches. After the ansible version is upgrade in sonic-mgmt docker, all branches will require this change. So, added labels for cherry-picking.

@yutongzhang-microsoft yutongzhang-microsoft deleted the yutonghznag/change_shebang branch July 2, 2025 07:50
mssonicbld pushed a commit to mssonicbld/sonic-mgmt that referenced this pull request Jul 2, 2025
…onic-net#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.
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202505: #19335

@mssonicbld
Copy link
Collaborator

Cherry-pick PR to msft-202412: Azure/sonic-mgmt.msft#484

vvolam pushed a commit to vvolam/sonic-mgmt that referenced this pull request Jul 3, 2025
…onic-net#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.
yejianquan pushed a commit that referenced this pull request Jul 3, 2025
…19258) (#19335)

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.

Co-authored-by: Yutong Zhang <90831468+yutongzhang-microsoft@users.noreply.github.com>
nissampa pushed a commit to nissampa/sonic-mgmt_dpu_test that referenced this pull request Aug 7, 2025
…onic-net#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.
ashutosh-agrawal pushed a commit to ashutosh-agrawal/sonic-mgmt that referenced this pull request Aug 14, 2025
…onic-net#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.
vidyac86 pushed a commit to vidyac86/sonic-mgmt that referenced this pull request Oct 23, 2025
…onic-net#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.
opcoder0 pushed a commit to opcoder0/sonic-mgmt that referenced this pull request Dec 8, 2025
…onic-net#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.

Signed-off-by: opcoder0 <110003254+opcoder0@users.noreply.github.com>
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Dec 16, 2025
…onic-net#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.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
AharonMalkin pushed a commit to AharonMalkin/sonic-mgmt that referenced this pull request Dec 16, 2025
…onic-net#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.

Signed-off-by: Aharon Malkin <amalkin@nvidia.com>
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Dec 21, 2025
…onic-net#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.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
@cyw233
Copy link
Contributor

cyw233 commented Dec 29, 2025

Cherry-pick PR to msft-202405: Azure/sonic-mgmt.msft#944

venu-nexthop pushed a commit to venu-nexthop/sonic-mgmt that referenced this pull request Jan 13, 2026
…onic-net#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.
gshemesh2 pushed a commit to gshemesh2/sonic-mgmt that referenced this pull request Jan 26, 2026
…onic-net#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.

Signed-off-by: Guy Shemesh <gshemesh@nvidia.com>
ytzur1 pushed a commit to ytzur1/sonic-mgmt that referenced this pull request Feb 2, 2026
…onic-net#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.

Signed-off-by: Yael Tzur <ytzur@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment