簡體   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