简体   繁体   English

如何在 CentOS8 上安装 Ansible

[英]How to install Ansible on CentOS8

I am trying to install ansible on CentOS 8 but no success, After searching google i did following steps我正在尝试在 CentOS 8 上安装 ansible 但没有成功,搜索谷歌后我做了以下步骤

yum install python3-pip
pip3 install ansible

but it shows following output and no ansible avaiable但它显示以下 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)

i tried to manually download and install but still no success我试图手动下载和安装但仍然没有成功

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)

then tried to deploy these packages but no success然后尝试部署这些包但没有成功

[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

You see one warning, which you should take very seriously if you don't want to destroy files, that were installed via yum packages.您会看到一个警告,如果您不想破坏通过 yum 软件包安装的文件,您应该非常认真地对待这些警告。 which is这是

Running pip install with root privileges is generally not a good idea.以 root 权限运行 pip 安装通常不是一个好主意。 Try pip3 install --user instead.尝试pip3 install --user代替。

I suggest to try using a virtualenv.我建议尝试使用 virtualenv。 Using a virtualenv reduces the probability to destroy an existing setup and allows you to have different package versions per virtualenv.使用 virtualenv 可以降低破坏现有设置的可能性,并允许您在每个 virtualenv 中拥有不同的 package 版本。 Just do not forget to activate your virtualenv before pip installing into it.只是不要忘记在 pip 安装到它之前激活您的 virtualenv。

Unfortunately Ansible has (had at least when I used it last time) a small issue, that it will not be able to install packages if you use a virtualenv which does not include system site packages, so I'm not 100% sure, you will be successful.不幸的是 Ansible 有一个小问题(至少在我上次使用它时),如果您使用不包含系统站点包的 virtualenv,它将无法安装包,所以我不能 100% 确定,你会成功的。

I try to walk you through following: 1.) install virtualenv (either with yum or with pip install, but in order to not destroy anything in your existing setup you'd use pip install with the --user option) 2.) create 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 the -U option我尝试引导您完成以下操作: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 use a virtualenv in order to avoid conflicts with existing packages. 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 以避免与现有软件包发生冲突。

You might try something like:您可以尝试以下方法:

sudo pip install --user virtualenv # or install virtualenv with yum if you know the package name. sudo pip install --user virtualenv # 或者如果您知道 package 名称,则使用 yum 安装 virtualenv。

then然后

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

now activate the virutalenv现在激活virutalenv

. /root/ansiblevenv/bin/activate . /root/ansiblevenv/bin/activate # do not forget the space between the. . /root/ansiblevenv/bin/activate #不要忘记之间的空格。 and the /和 /

Now check, that the active python is the one of the virtualenv现在检查,活动的 python 是 virtualenv 之一

type python

you should see /root/ansiblevenv/bin/python instead if 'usr/bin/python' if not the virtualenv is not enabled properly你应该看到/root/ansiblevenv/bin/python如果 'usr/bin/python' 如果不是 virtualenv 没有正确启用

Now update pip (just in case)现在更新 pip(以防万一)

pip install -U pip

and now try to install ansible现在尝试安装 ansible

pip install -U ansible

You can also use the below steps to install Ansible on CentOS 8.您还可以使用以下步骤在 CentOS 8 上安装 Ansible。

Step 1: Installation of EPEL repository第 1 步:安装 EPEL 存储库

Ansible is not available in the default repository. Ansible 在默认存储库中不可用。 So, to install it, we have to enable the EPEL repository.因此,要安装它,我们必须启用 EPEL 存储库。 Firstly, we are going to install epel-release .首先,我们要安装epel-release Use the below command to install it.使用下面的命令来安装它。

sudo dnf -y install epel-release

Note: you can also use yum command instead of dnf注意:你也可以使用yum命令代替dnf

Step 2: Installing Ansible on CentOS 8第 2 步:在 CentOS 8 上安装 Ansible

let's install Ansible.让我们安装 Ansible。 Use the below command for this installation.使用以下命令进行此安装。

sudo dnf -y install ansible

Once the installation is completed, then use the below command to verify the version.安装完成后,使用以下命令验证版本。

ansible --version

That's it.而已。 But you can read more about ansible installation on CentOS8 related commands for managed node and other details.但是您可以阅读更多关于 ansible 在 CentOS8 上安装受管节点的相关命令和其他详细信息。 You can visit my blog post for Ansible.您可以访问我关于 Ansible 的博客文章。 You can use the URL below.您可以使用下面的 URL。

How to install and configure Ansible on CentOS 8 如何在 CentOS 8 上安装和配置 Ansible

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

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