Centos 6 中带有 SCL Python 2.7 的 Ansible 加密警告

Ansible cryptography warning with SCL Python 2.7 in Centos 6

鉴于以下情况:

[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

为什么我会得到这个结果?

[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 版本甚至有警告,所以它绝对是与远程主机无关的本地事物:

[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

看来 Ansible 正在调用 cryptography 的基础 Python 版本。这是这个版本的 Ansible 中的错误还是与 SCL 的工作方式有关?我需要做什么来修复它?

编辑以添加更多疑难解答

问题与 Ansible 调用 Python 本身的方式有关,因为 /usr/bin/ansible 中的 she-bang 是 #!/usr/bin/python。如果我将其更改为 #!/usr/bin/env python 我会得到一个不同但仍然显示停止的错误:

[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

看来问题出在 Ansible 上。

仍在寻找修复或解决方法...

正如您所确定的,是的,Ansible always uses /usr/bin/python,而且这不太可能很快改变。

密码学库促使您升级 Python 的版本。更改 Python 的系统版本可能相当危险,尤其是在 CentOS 上,因为 yum 使用它。

摆脱警告的最佳选择是升级到 CentOS 7,因为它将包括 Python 2.7。或者,您可以习惯于收到弃用警告,因为使用 CentOS 的一部分是在使用旧软件。