ansible_modules
ansible_modules copied to clipboard
[Feature]: Migrate to py3.6+ features
ISSUE TYPE
- Feature Idea
SUMMARY
Need to migrate to Py3.6+ features
- f-strings
- Static Typing (Add mypy to testing as well)
I think I'm going to hold off on this at the moment and close out this issue.
I would like to respectfully question the decision to require python 3.
How is this decision reasonable when not working with python 2 will cause this module to be practically unusable on any EL except EL8 currently?
Python 3 is available for EL7 but it is practically unusable for Ansible use due to missing SELinux bindings.
I've gotten around this at $prev_employer by installing selinux
via PyPi, I believe.
I know it's possible and once we implement these, maybe add that stuff to documentation, but I've used Python 3.6 on RHEL/CENTOS 7 successfully in the past.
This is pretty low on the list at the moment as that is why it's closed for the time being, but I do appreciate your insight and will make sure to keep this in for consideration when moving to Python 3.6+.
I do not think selinux-python is installable in any way other than binary package since it depends on the selinux library version.
There are tons of references to this and everyone says Ansible is practically unusable on EL6/EL7 without manually compiling. Practically unusable = netbox module works, but anything requiring selinux (template, file, ...) does not work.
So I've ripped out anything netbox-community and gone back to the bundled modules. This will be a huge problem after Ansible 2.10 - anyone on EL older than 8 will be stuck with Ansible 2.9.
Edit: netbox-community is already incompatible with python 2.
I do not think selinux-python is installable in any way other than binary package since it depends on the selinux library version.
Did you try my suggestion above by installing selinux
via PyPi? I was using Python 3.6 on RHEL7 at my previous employer and it worked fine for templating, modules, etc. I never had any issues with it after I installed that Python package within the virtualenv I was using.
I would also suggest posting the issues you're seeing with your environment and I will be more than happy to help to a certain extent. My choice to not support anything lower than Python 3.6 is due Python 2 being EOL already and I'd rather not try to maintain backwards compatibility.
I was not aware there was any code that was not causing it to run on Python 2.
Error on python 2:
TypeError: super() takes at least 1 argument (0 given)
The selinux cannot be installed with anything except rpm or compiling based on every article I read about this (several), the package libselinux-python
depends on the installed SELinux library version.
As for selinux - getting selinux
from pypi worked. Strange, I do not know why all the discussions online claimed it is impossible.
Please excuse me for beating the dead horse but if you are using python 3 how is it working for you?
For me both the reboot
and template
modules are not working correctly. At least for template
there is a workaround in ansible/ansible#56243 but it seems like there are a lot of issues with python 3. The playbook I have tested so far is very simple but already there is trouble and I need to find a workaround for ansible/awx#5016.
My point being that it would be really great if python 2 would be supported for just a while longer. EL7 will support python 2 for several more years.
What are the errors you're encountering?
Have you made sure to set the ansible_python_interpreter
to location of Python3?
The netbox-community module works with python 3. I meant that Ansible itself has many -- in my opinion very important -- problems with python 3.
In earlier comment it was claimed that it works with python 2 but in https://github.com/netbox-community/ansible_modules/issues/88#issuecomment-609429012 is the error that I got on python 2.
These will not support Python2 at all. I didn't think any code was implemented that worked with just Python3, but I was wrong, and not going to modify the code to become backwards compatible with Python2.
If you post error messages, I can attempt to help you solve your issues, but like you said the issue is with the main Ansible functionality and not these modules.
Just to reiterate, I'm pretty sure most of my colleagues are using Python3 with Ansible without any issues so it is definitely something environment specific you need to overcome and I've used it within several different Docker containers and Ubuntu/CentOS machines as well without any modifications out of the box.
I guess that is understandable with the python 2 already out of support. At the same time very disappointing because Ansible with python 3 has some very annoying bugs. Thanks for taking your time to explain the project team's stance on this.
I am going to flog this dead horse one last time to clarify what I've learnt lately in case someone else tries to use this collection on EL7 and hits the same problems.
Ansible does not work properly with python 3 on EL7 if SELinux is needed - which is a requirement for many. This might change if Red Hat would decide to ship the SELinux binaries for Python 3 - numerous bugzillas have been open for years so don't hold your breath with EL7 being in maintenance support phase.
There is no way to get SELinux bindings to python 3, the selinux module installed with pip is just a dummy module that changes SELinux operations to nops. That means two options:
- Without installing the selinux module, any Ansible module using SELinux will fail with an error.
- After installing the selinux module for python 3, SELinux labels cannot be modified and for example template Ansible module will always create files with label
admin_home_t
(due to temporary file inheriting the label from home directory) which renders the module useless.
@FragmentedPacket states that he has used Python 3 with Ansible, which is possible, but not with both SELinux and EL7.
Options could be to use separate playbooks with NetBox on one playbook that is run with python 3 and another with operations needing SELinux run with python 2. It is apparently also possible to switch ansible_python_interpreter
to python 3 on task level (for tasks using the NetBox collection) but it seems to incorrectly use python 2 in some cases.
Edit: the situation with python 3 might be worked around by using the SCL also.
I use RHEL7 today with Python3.7 and Ansible and Ansible Tower. It wasn't the easiest to get working but it is definitely possible. We compiled Python3.7 and got SELinux module working. I can't remember the details as it was a while ago now.
Its not a good situation as Ansible Tower requires RHEL or CentOS, but only the recent RHEL8/CentOS8 has real support for Python3. And then Python2 is of course EOL, so it just makes everything complicated.
I don't think this should stop the move to Python3 though. Just because RHEL can't get it together shouldn't stop other projects.
I'm closing this out as it has digressed from the main issue.