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

问题描述 投票:0回答:3

鉴于以下情况:

[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 上。

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

python python-2.7 ansible centos6
3个回答
1
投票

正如您所确定的,是的,Ansible 始终使用

/usr/bin/python
,而且这一点不太可能很快改变。

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

yum
使用它。

消除警告的最佳选择是升级到 CentOS 7,因为它将包含 Python 2.7。或者,您也可以习惯出现弃用警告,因为使用 CentOS 的一部分就是使用旧软件。


0
投票

我知道现在不应该运行 Centos 6..但万一有人遇到困难.. 您被困在特定版本上,您可以执行以下操作:

# 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 是适用于 Python 3.6 的最后一个版本。 Cryptography 36.0.2 是最后一个可用版本,不提供折旧警告并且具有工作轮。


0
投票

假设无法升级操作系统,您可以使用 SCL 安装 python27,并将其添加到 playbook 的顶部:

  environment:
    LD_LIBRARY_PATH: "/opt/rh/python27/root/usr/lib64"
  vars:
    ansible_python_interpreter: "/opt/rh/python27/root/usr/bin/python2.7"

如果您的代码适用于多个主机,您还可以将

ansible_python_interpreter
行添加到您的清单中,并为每个命令设置
environment

这些设置基本上就是

scl enable
设置的环境。那里还有其他环境变量,但我的代码可以使用这个最小配置。

信用:https://listman.redhat.com/archives/sclorg/2019-October/001149.html

© www.soinside.com 2019 - 2024. All rights reserved.