Closed aueam closed 1 year ago
Thanks @aueam for your contribution,
The shebang is a requirement of Ansible and how Ansible work, the shebang in modules is not useless, even though they are not executable (and were nevert meant to be executable as is).
Ansible does some magic packaging before they get transferred to the target and executed, including some module utils which you see in the modules. (AFAIR the shebang will be replaced to whatever ansible_python_interpreter points to)
Read more about the requirement https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_documenting.html#python-shebang-utf-8-coding
Interesting, @resmo. I believe the ansible_python_interpreter
logic simply replaces the #!/usr/bin/python
shebang by whatever is Python on the target machine (for example #!/usr/bin/python3
) and then the particular file is executed (if it is meant to be executed). In this particular case I believe these files are not executed, but instead imported as Python modules.
OTOH, it is easily possible that I'm wrong here, so please could you show us what ansible
does (or could do) with those files to make them executable by utilizing their shebang?
Thank you.
In addition, for the plugins/inventory/vultr.py
file the current shebang does not follow the rule you are referring to :-).
indeed, ironically there shouldn't be a shebang in an inventory plugin because it's executed on the controller.
I found this: https://docs.ansible.com/ansible/latest/dev_guide/testing/sanity/shebang.html
So it looks like ansible really requires shebang in modules even they are not executable.
I think this bug report could be closed.
Describe the bug
The listed files shouldn't be runnable with python because they have relative imports. But thanks to the shebangs they are runnable, which is wrong because it always throws an error.
listed files:
To Reproduce Steps to reproduce the behavior:
chmod +x vultr.py
Expected behavior I expected them not to be runnable.
Desktop (please complete the following information where applicable: