3

Given the following:

[root@vmutil01 ~]# cat /etc/issue
CentOS release 6.7 (Final)

[root@vmutil01 ~]# yum -y install centos-release-SCL

[ ... ]

[root@vmutil01 ~]# yum -y install python27

[ ... ]

[root@vmutil01 ~]# scl enable python27 bash
[root@vmutil01 ~]# python -V
Python 2.7.5

Why am I getting this result?

[root@vmutil01 ansible]# ansible centos7_hosts -m ping
/usr/lib64/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of cryptography will drop support for Python 2.6
  DeprecationWarning
vmcentos7dev | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Ansible version even has the warning so it's definitely a local thing not related to the remote hosts:

[root@vmutil01 ansible]# ansible --version
/usr/lib64/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of cryptography will drop support for Python 2.6
  DeprecationWarning
ansible 2.0.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

It would appear that Ansible is calling the base Python version of cryptography. Is this a bug in this version of Ansible or related to the way SCL works? What do I need to do to fix it?

Edit to add more troubleshooting

The problem is related to the way Ansible is invoking Python itself as the she-bang in /usr/bin/ansible is #!/usr/bin/python. If I change that to #!/usr/bin/env python I get a different, but still show-stopping, error:

[root@vmutil01 ansible]# ansible --version
Traceback (most recent call last):
  File "/usr/bin/ansible", line 39, in <module>
    from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
ImportError: No module named ansible.errors

So it seems the problem is with Ansible.

Still looking for a fix or workaround...

JonB
  • 836
  • 1
  • 11
  • 15
  • Are you opening a new shell after enabling the scl Python before running Ansible? What happens if you try `scl enable python27 "ansible --version"` – ydaetskcoR May 11 '16 at 19:49
  • Also, any particular reason that you can't run Ansible from a machine with an OS that isn't so restrained? – ydaetskcoR May 11 '16 at 19:50
  • Direct execution using `scl enable python27 "ansible --version"` gets the same result and if I can't find a reasonable solution I guess I will have to switch over to Ubuntu. – JonB May 11 '16 at 20:04

2 Answers2

2

As you ascertained, yes, Ansible always uses /usr/bin/python, and that is unlikely to change soon.

The cryptography library is pushing you to upgrade your version of Python. Changing the system version of Python can be rather dangerous, especially on CentOS, since yum uses it.

Your best choice for getting rid of the warning is to upgrade to CentOS 7, as that will include Python 2.7. Alternatively, you can get used to having deprecation warnings, since part of using CentOS is using old software.

Xiong Chiamiov
  • 13,076
  • 9
  • 63
  • 101
  • That's pretty much the conclusion I was coming to. I definitely would not consider messing with the base Python install on a RH-based system because of the system dependencies. I provisioned an Ubuntu 16.04 host for this purpose but might use CentOS 7. – JonB May 12 '16 at 10:04
  • I suppose one more option would be to use a Docker container that's based on a more recent release to run Ansible; that sort of dependency isolation is one of the primary benefits of containers. However, that seems like overkill to me, and likely more of a pain. – Xiong Chiamiov May 12 '16 at 14:45
0

I know one should not run Centos 6 nowadays.. but in case anyone is struggling.. You're stuck on specific versions and here is what you can do:

# YOU NEED THIS VERSION FOR WHEEL SUPPORT
pip3.6 install -q --upgrade pip==20.1.0
pip3.6 install -q wheel
pip3.6 install -q --upgrade ansible-core==2.11.12 virtualenv==20.14.1 platformdirs==2.4.0 zipp==3.4.0 cryptography==36.0.2

Ansible 2.11 is the last version available for Python 3.6. Cryptography 36.0.2 is the last version available that gives no depreciation warnings and has a working wheel.

Alex R
  • 637
  • 1
  • 8
  • 20