繁体   English   中英

如何在 CentOS8 上安装 Ansible

[英]How to install Ansible on CentOS8

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

yum install python3-pip
pip3 install ansible

但它显示以下 output 并且没有可用的 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 软件包安装的文件,您应该非常认真地对待这些警告。 这是

以 root 权限运行 pip 安装通常不是一个好主意。 尝试pip3 install --user代替。

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

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

我尝试引导您完成以下操作:1.)安装 virtualenv(使用 yum 或 pip 安装,但为了不破坏现有设置中的任何内容,您将使用 pip 安装和--user选项)2.)创建a virtualenv for python3 with system site packages enabled as you will have issues with ansible and package installation otherwise 3.) enable your virtualenv (Do not forget this.) 4.) Check that you really enabled your virtualenv 5.) pip install ansible with -U 选项

Try out ansible and specify the path to the python executable of your virtualenv in with the ansible_python_interpreter setting of ansible ( https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html ) Collecting python-setuptools You might try to使用 virtualenv 以避免与现有软件包发生冲突。

您可以尝试以下方法:

sudo pip install --user virtualenv # 或者如果您知道 package 名称,则使用 yum 安装 virtualenv。

然后

virtualenv -p $(which python3) /root/ansiblevenv --system-site-packages

现在激活virutalenv

. /root/ansiblevenv/bin/activate . /root/ansiblevenv/bin/activate #不要忘记之间的空格。 和 /

现在检查,活动的 python 是 virtualenv 之一

type python

你应该看到/root/ansiblevenv/bin/python如果 'usr/bin/python' 如果不是 virtualenv 没有正确启用

现在更新 pip(以防万一)

pip install -U pip

现在尝试安装 ansible

pip install -U ansible

您还可以使用以下步骤在 CentOS 8 上安装 Ansible。

第 1 步:安装 EPEL 存储库

Ansible 在默认存储库中不可用。 因此,要安装它,我们必须启用 EPEL 存储库。 首先,我们要安装epel-release 使用下面的命令来安装它。

sudo dnf -y install epel-release

注意:你也可以使用yum命令代替dnf

第 2 步:在 CentOS 8 上安装 Ansible

让我们安装 Ansible。 使用以下命令进行此安装。

sudo dnf -y install ansible

安装完成后,使用以下命令验证版本。

ansible --version

而已。 但是您可以阅读更多关于 ansible 在 CentOS8 上安装受管节点的相关命令和其他详细信息。 您可以访问我关于 Ansible 的博客文章。 您可以使用下面的 URL。

如何在 CentOS 8 上安装和配置 Ansible

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM