1. 程式人生 > >通過自制yum源離線安裝 ansible

通過自制yum源離線安裝 ansible

系統環境:     Red Hat Enterprise Linux Server release 7.5 (Maipo)

Python版本:  

Python 2.7.5

       由於在工作環境中,經常遇到批量安裝的伺服器,不具備連線網際網路的條件。同時通過簡單的下載安裝 ansible 原始碼安裝,又會遇到各種奇葩問題,推薦使用自制 yum 源方法,然後使用 yum安裝 ansible。

一、準備一臺可以連線網際網路的相同版本系統的作業系統(安裝環境一樣),使用yumdownloader工具下載ansible安裝包以及所有依賴包。並以 root 身份安裝 Yumdownloader工具:

# yum  -y install  yum-utils

建立兩個資料夾,用於存放依賴的安裝包

# mkdir   /root/packages1    /root/packages2

由於預設的源裡沒有 ansible,需要安裝 fedora epel源:

# yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

下載 ansible 和 所有依賴包

# yumdownloader --resolve --destdir /root/packages1   ansible

# yumdownloader --resolve --destdir /root/packages2   createrepo

 

二、將上面下載的所有 rpm 安裝包打包,傳輸到需要批量的任意一臺伺服器上,並解壓到指定的資料夾裡面

# tar  -Jcvf  packages1.tar.xz   packages1

# tar  -Jcvf  packages2.tar.xz   packages2

# tar -Jxvf    packages1.tar.xz   -C  /mnt/

# tar -Jxvf    packages2.tar.xz   -C  /mnt/

 

1.首先建立 安裝createrepo   進入 /mnt/packages2 目錄中

# rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm

# rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm

# rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm

 

2. 然後使用createrepo生成符合要求的yum倉庫,執行:

# cd  /mnt

# createrepo /packages1

Spawning worker 0 with 25 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

 

三、配置本地 yum源

把當前存在 yum 做備份,並移走別的目錄

# vi  /etc/yum.repos.d/ansible.repo

[ansibel]

name=my local ansible

baseurl=file:///mnt/packages1

enabled=1

gpgcheck=0

儲存退出,然後執行:

# yum clean all

# yum makecache

 

四、使用 yum安裝 ansible

# yum -y install ansible

驗證安裝成功:

ansible --version

ansible 2.7.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Feb 20 2018, 09:19:12) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]


 

         備註:由於以上環境依賴存在差異,僅供參考。