python - 如何在 CentOS8 上安装 Ansible

标签 python ansible centos

我正在尝试在 CentOS 8 上安装 ansible 但没有成功,在搜索谷歌后我做了以下步骤

yum install python3-pip
pip3 install ansible

但它显示以下输出并且没有可用的ansible
[root@okd1 ~]# pip3 install ansible
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: ansible in ./.local/lib/python3.6/site-packages
Requirement already satisfied: jinja2 in ./.local/lib/python3.6/site-packages (from ansible)
Requirement already satisfied: PyYAML in /usr/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: cryptography in /usr/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: MarkupSafe>=0.23 in ./.local/lib/python3.6/site-packages (from jinja2->ansible)
Requirement already satisfied: idna>=2.1 in /usr/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: six>=1.4.1 in /usr/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in /usr/lib64/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: pycparser in /usr/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.7->cryptography->ansible)

我试图手动下载和安装但仍然没有成功
curl -o ansible.rpm https://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-2.8.5-1.el7.ans.noarch.rpm

[root@okd1 ~]# yum install ansible.rpm
Last metadata expiration check: 0:09:14 ago on Wed 25 Sep 2019 05:39:22 PM EDT.
Error: 
 Problem: conflicting requests
  - nothing provides python-setuptools needed by ansible-2.8.5-1.el7.ans.noarch
  - nothing provides python-six needed by ansible-2.8.5-1.el7.ans.noarch
  - nothing provides PyYAML needed by ansible-2.8.5-1.el7.ans.noarch
  - nothing provides python-jinja2 needed by ansible-2.8.5-1.el7.ans.noarch
  - nothing provides python-paramiko needed by ansible-2.8.5-1.el7.ans.noarch
  - nothing provides python2-cryptography needed by ansible-2.8.5-1.el7.ans.noarch
  - nothing provides sshpass needed by ansible-2.8.5-1.el7.ans.noarch
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

然后尝试部署这些包但没有成功
[root@okd1 ~]# pip3 install python-setuptools
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting python-setuptools
  Could not find a version that satisfies the requirement python-setuptools (from versions: )
No matching distribution found for python-setuptools
[root@okd1 ~]# 
[root@okd1 ~]# pip2 install python-setuptools
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip2 install --user` instead.
Collecting python-setuptools
  Could not find a version that satisfies the requirement python-setuptools (from versions: )
No matching distribution found for python-setuptools

最佳答案

您会看到一个警告,如果您不想破坏通过 yum 软件包安装的文件,您应该非常认真地对待这些警告。这是

Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead.



我建议尝试使用 virtualenv。使用 virtualenv 可以降低破坏现有设置的可能性,并允许您为每个 virtualenv 提供不同的包版本。只是不要忘记在 pip 安装到它之前激活你的 virtualenv。

不幸的是,Ansible 有一个小问题(至少在我上次使用它时),如果您使用不包含系统站点包的 virtualenv,它将无法安装包,所以我不能 100% 确定,你会成功的。

我尝试引导您完成以下操作:
1.) 安装 virtualenv(使用 yum 或 pip install,但为了不破坏现有设置中的任何内容,您可以使用带有 --user 选项的 pip install)
2.) 为 python3 创建一个 virtualenv 并启用系统站点包,否则你将遇到 ansible 和包安装问题
3.)启用你的virtualenv(不要忘记这个!)
4.) 检查你是否真的启用了你的 virtualenv
5.) pip install ansible 使用 -U 选项

尝试 ansible 并使用 ansible 的 ansible_python_interpreter 设置指定 virtualenv 的 python 可执行文件的路径( https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html )
收集 python-setuptools
您可能会尝试使用 virtualenv 以避免与现有软件包发生冲突。

您可以尝试以下方法:
sudo pip install --user virtualenv # 如果你知道包名,或者用 yum 安装 virtualenv。

然后
virtualenv -p $(which python3) /root/ansiblevenv --system-site-packages
现在激活virutalenv
. /root/ansiblevenv/bin/activate # 不要忘记 .和/

现在检查,事件的 python 是 virtualenv 之一
type python
你应该看到 /root/ansiblevenv/bin/python相反,如果 'usr/bin/python' 如果不是,则 virtualenv 未正确启用

现在更新点子(以防万一)
pip install -U pip
现在尝试安装ansible
pip install -U ansible

关于python - 如何在 CentOS8 上安装 Ansible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58107029/

相关文章:

linux - Ansible sudo 不起作用

centos - Vagrant 如何在 CentOS 上自动安装 Docker?

python - opencv aruco estimatePoseSingleMarkers python

python - 如何取消 Pandas 数据透视表的透视?

python - 基本的 Python 代码不起作用

ansible:将列表中的一个元素过滤为字符串

python - 使用 dask 分布式时 OMP_NUM_THREADS 出错

ansible - 其他服务器的 SSH key 存储在哪里? - 安西 bool

node.js - 用于应用程序身份验证的 OpenLDAP 本地配置

java - 在 eclipse 中创建了一个 java 测试脚本,如何在 headless Linux CentOS VM 中运行它?