【问题标题】:Ansible cryptography warning with SCL Python 2.7 in Centos 6Centos 6 中 SCL Python 2.7 的 Ansible 加密警告
【发布时间】:2016-09-07 09:07:16
【问题描述】:

鉴于以下情况:

[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 之前启用 scl Python 后是否要打开一个新的 shell?如果你尝试scl enable python27 "ansible --version" 会发生什么
  • 另外,有什么特殊原因导致您无法在操作系统不受限制的机器上运行 Ansible?
  • 使用scl enable python27 "ansible --version" 直接执行会得到相同的结果,如果找不到合理的解决方案,我想我将不得不切换到 Ubuntu。

标签: python python-2.7 ansible centos6


【解决方案1】:

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

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

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

【讨论】:

  • 这几乎就是我得出的结论。由于系统依赖性,我绝对不会考虑在基于 RH 的系统上安装基础 Python。为此,我配置了一个 Ubuntu 16.04 主机,但可能使用 CentOS 7。
  • 我想另一种选择是使用基于更新版本的 Docker 容器来运行 Ansible;这种依赖隔离是容器的主要好处之一。然而,这对我来说似乎有点矫枉过正,而且可能更痛苦。
猜你喜欢
  • 2017-02-26
  • 1970-01-01
  • 2017-08-15
  • 2018-02-08
  • 1970-01-01
  • 2021-01-06
  • 2018-10-10
  • 2019-02-06
  • 1970-01-01
相关资源
最近更新 更多