如何在CentOS8上安装Ansible

时间:2019-09-25 21:53:37

标签: python ansible centos

我正在尝试在CentOS 8上安装ansible,但没有成功,在搜索google之后,我确实按照以下步骤操作了

yum install python3-pip
pip3 install 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

2 个答案:

答案 0 :(得分:0)

您会看到一个警告,如果您不想破坏通过yum软件包安装的文件,则应该非常重视。

  

使用root特权运行pip安装通常不是一个好主意。   尝试使用--user

我建议尝试使用virtualenv。使用virtualenv可以减少破坏现有设置的可能性,并允许您为每个virtualenv使用不同的软件包版本。只是不要忘记在将pip安装到其中之前激活您的virtualenv。

不幸的是,Ansible(至少在我上次使用它时)有一个小问题,即如果您使用不包含系统站点软件包的virtualenv,它将无法安装软件包,因此我不是100%当然,你会成功的。

我尝试向您介绍以下内容: 1.)安装virtualenv(使用yum或pip install,但为了不破坏现有设置中的任何内容,请使用带有sudo pip install --user virtualenv选项的pip install) 2.)为启用了系统站点程序包的python3创建virtualenv,因为否则将无法安装ansible和程序包 3.)启用您的virtualenv(请不要忘记这一点!) 4.)检查您是否真的启用了virtualenv 5.)使用-U选项安装pip ansible

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

您可以尝试以下方法:

virtualenv -p $(which python3) /root/ansiblevenv --system-site-packages#或在知道软件包名称的情况下用yum安装virtualenv。

然后

. /root/ansiblevenv/bin/activate

现在激活virutalenv

type python#不要忘记之间的空格。和/

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

/root/ansiblevenv/bin/python

如果'usr / bin / python'如果未正确启用virtualenv,则应该改用pip install -U pip

现在更新点数(以防万一)

pip install -U ansible

现在尝试安装ansible

{{1}}

答案 1 :(得分:0)

您还可以按照以下步骤在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

就是这样。但是您可以阅读更多有关在CentOS8相关命令上的ansible安装的信息,以获取受管节点和其他详细信息。您可以访问我的Ansible博客文章。您可以使用下面的网址。

How to install and configure Ansible on CentOS 8