離線安裝ansible方法


在連接外網環境下我們安裝ansible直接使用yum install

yum install ansible -y

但是在內網機上要去這樣安裝,就沒法直接用了,沒有網絡下載源,這時候如果包少,我們可以去rpm包網站搜索下來手動一個個傳進去rpm安裝即可,但是依賴較多就麻煩了。

安裝ansible 依賴包有15個,15個我們也可以手動一個個rpm還可以, 但是遇到其它包中又有依賴包,依賴幾十個,順序先后都是問題,這時候我們不能用rpm一個個安裝了。

一、下載安裝包及依賴

首先找一台離線服務器版本相同的linux虛擬機

1.下載yumdownloadonly插件安裝
yum install yum-plugin-downloadonly
2.安裝安裝epel源
yum install -y epel-release
3、下載所需安裝包,只下載不安裝
#yum 下載rpm包到指定目錄,只下載不安裝
yum install  --downloadonly --downloaddir=路徑  安裝包名
4、下載readline-devel包
yum install  --downloadonly --downloaddir=/root/ansible ansible
5、安裝createrepo
yum install createrepo
6、創建軟件包文件
createrepo /root/ansible/

createrepo后在ansible文件夾下看到repodata文件夾,在文件夾下可看到如下創建的repomd.xml

7、打包已下載的軟件包,傳到內網機
tar -czvf ansible.tar.gz /root/ansible

二、拷貝到內網

1、解壓
tar -zxvf ansible.tar.gz -d /root/
2、制作yum源文件

先備份之前的文件

mv /etc/yum.repos.d/* /etc/yum.repos.d/backup/

制作yum源

touch myyum.repo
vim myyum.repo

[myyum]
name=local resource
baseurl=file:///root/ansible
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

更新yum

yum clean all
yum update
yum repolist
3.執行安裝
yum install ansible -y

在執行安裝的時候還是沒有裝成功,報錯了

Total                                                                                                                                                         56 MB/s |  21 MB  00:00:00     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


The GPG keys listed for the "local resource" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.


 Failing package is: python2-jmespath-0.9.4-2.el7.noarch
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

這里是軟件開發商在釋出 RPM 文件時,會在其中添加數字簽名,並釋出用於驗證數字簽名的公鑰。使用 rpm 安裝軟件時,rpm 會首先根據系統中已有的公鑰去驗證 RPM 文件的數字簽名。gpg keys 就是公鑰。所以在安裝的時候會比對已有的公鑰,發現不正確,報錯了

可以直接跳過數字簽名檢查安裝加上--nogpgcheck

sudo yum -y install ansible --nogpgcheck


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM