系统 环境: 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)]
备注:由于以上环境依赖存在差异,仅供参考。
转载于:https://blog.51cto.com/pengjc/2328291