如何在CentOS8上安装Ansible

0 人关注

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

yum install python3-pip
pip3 install ansible

但它显示了以下的输出,并且没有Ansible avaiable。

[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
    
1 个评论
Gang
未来的趋势是Fedora,然后是centos,然后是rhel,你总是能得到新的软件包
python
ansible
centos
ImranRazaKhan
ImranRazaKhan
发布于 2019-09-26
2 个回答
gelonida
gelonida
发布于 2020-07-19
已采纳
0 人赞同

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

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

我建议尝试使用virtualenv。使用virtualenv可以减少破坏现有设置的概率,并允许你在每个virtualenv中拥有不同的软件包版本。只是不要忘记在pip安装到虚拟环境之前激活你的虚拟环境。

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

我试着指导你完成以下工作。 1.) 安装virtualenv(可以用yum或者pip安装,但是为了不破坏你现有的设置,你应该使用pip安装,并选择 --user ) 2.) 为python3创建一个虚拟环境,并启用系统站点包,否则你会在ansible和包的安装方面遇到问题。 3.) 启用你的virtualenv(不要忘记这一点!)。 4.)检查你是否真的启用了你的virtualenv 5.) pip安装ansible,使用-U选项

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

You might try something like:

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

如果'usr/bin/python',你应该看到 /root/ansiblevenv/bin/python ,而不是'usr/bin/python',如果不是的话,virtualenv没有被正确启用。

现在更新管道(以备不时之需)

pip install -U pip

现在尝试安装ansible

pip install -U ansible

Linux Gurus
Linux Gurus
发布于 2020-07-19
0 人赞同

你也可以使用下面的步骤在CentOS 8上安装Ansible。

第1步:安装EPEL资源库

Ansible在默认的版本库中是不可用的。所以,为了安装它,我们必须启用EPEL仓库。首先,我们要安装 epel-release 。使用下面的命令来安装它。

sudo dnf -y install epel-release

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

第二步:在CentOS 8上安装Ansible

让我们来安装Ansible。使用下面的命令进行安装。

sudo dnf -y install ansible