Ansible formula modifies PYTHONPATH and causes Python scripts within playbooks to fail #35647
Comments
Yep, our packaging is doing this. This will take some creativity to resolve. A workaround may be using It's possible that instead of setting PYTHONPATH we could write shims similar to the one we use to invoke |
Yes, I agree that
I'd rather avoid this approach as it's more complex and thus will be more error-prone and harder to maintain. |
Wait, if I'm understanding you correctly, you're proposing that users change all the python scripts called by their Ansible tasks to disregard PYTHONPATH? This is a non-starter. The same playbooks and scripts should work on OS X just like other platforms. It's worth noting that my scripts don't even have a shebang--they are executed by calling python directly ("python3 ../path/to/script.py"). I'm not even clear on why the formula needs to vendorize modules, but then again I'm not at all familiar with Homebrew internals. I feel like it should depend upon other formulas that install the requisite modules in the Homebrew PYTHONPATH (/usr/local/Cellar/python3/...). |
Well, users can do that or they use |
Not trying to be difficult, but what makes this notable? Does this prevent you from invoking python with
Your feeling is probably transferred from other packaging systems which work this way; Homebrew does not work this way, for reasons including avoiding the overhead of packaging libraries without many dependents that are already handled well by language-specific packaging tools. |
Fair enough. I'm not trying to be difficult either (perhaps my tone was a bit aggressive in the previous response).
Also a fair point. If it isn't feasible to fix this issue in the Ansible formula directly, would it be a suitable compromise to add some big warnings to users after installation that playboook-executed Python scripts may break, and if that is a problem to install Ansible via pip instead? |
|
See my issue #35914. It might have to do with the rewrite of the shebang from the original |
I reference this issue in my Ansible issue regarding the Ansible pip module getting "confused" between the Ansible Homebrew site-packages and the main /usr/local site-packages. It appears this topic explains the problem I was having. In the end I uninstalled the ansible homebrew and did:
|
Yes, that's because pip thinks it's okay to remove any existing packages it finds in sys.path when it's installing a new version of the package. We can't readily work around it. Sorry! |
Are there action items here, or is this wontfix (or something else)? |
Are there any plans to fix this? This is causing my playbook to fail cause Ansible can't find the required modules it needs, specifically MySQLdb which is needed for the mysql_db (http://docs.ansible.com/mysql_db_module.html#notes) |
No, unfortunately not. For your particular case @johnscancella submit a PR to include that module to Ansible. |
The Ansible formula appears to modify PYTHONPATH internally to vendored versions of some modules. This causes Python scripts executed within Ansilbe playbooks to potentially fail if there are module conflicts.
Test Ansible playbook tasks:
Output:
Note the first two entries:
These entries alter the Python execution environment within playbooks and can cause scripts to fail.
I see this error trying to execute a Python 3 script from within an ansible playbook, failing on a PyYAML module conflict:
Affected playbook tasks:
Output:
The same script runs normally when run from a bash shell (ie, not within an Ansible playbook). The playbook runs normally (ie, the Python 3 script runs without error) on an Ubuntu box with the same Ansible version.
The text was updated successfully, but these errors were encountered: