系统 环境: Red Hat Enterprise Linux Server release 7.5 (Maipo)python
Python版本: Python 2.7.5sql
因为在工做环境中,常常遇到批量安装的服务器,不具有链接互联网的条件。同时经过简单的下载安装 ansible 源码安装,又会遇到各类奇葩问题,推荐使用自制 yum 源方法,而后使用 yum安装 ansible。bash
1、准备一台能够链接互联网的相同版本系统的操做系统(安装环境同样),使用yumdownloader工具下载ansible安装包以及全部依赖包。并以 root 身份安装 Yumdownloader工具:服务器
# yum -y install yum-utils
建立两个文件夹,用于存放依赖的安装包python2.7
# mkdir /root/packages1 /root/packages2
因为默认的源里没有 ansible,须要安装 fedora epel源:ide
# 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
2、将上面下载的全部 rpm 安装包打包,传输到须要批量的任意一台服务器上,并解压到指定的文件夹里面url
# 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仓库,执行:sqlite
# 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
3、配置本地 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
4、使用 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)]
备注:因为以上环境依赖存在差别,仅供参考。