环境说明:centos7.x ,ansible-2.9.25,python3.7
一、安装包制作(有网络的机器)
1.安装yum-utils
yum -y install yum-utils
2.安装epel源
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
3.获取ansible依赖包和安装包
yumdownloader --resolve --destdir /tmp/ansible ansible
4.获取createrepo的依赖包和安装包
yumdownloader --resolve --destdir /tmp/ansible createrepo
5.增加自动部署脚本,/tmp/ansible/init.sh
#!/bin/bash
#安装createrepo
rpm -ivh $(pwd)/deltarpm-3.6-3.el7.x86_64.rpm
rpm -ivh $(pwd)/python-deltarpm-3.6-3.el7.x86_64.rpm
rpm -ivh --force --nodeps $(pwd)/createrepo-0.9.9-28.el7.noarch.rpm
#制作离线源
createrepo /tmp/ansible
#重命名系统源
cd /etc/yum.repos.d/
rename repo repo.bak *repo
cd -
#新增yum源文件
cat > /etc/yum.repos.d/ansible.repo <<EOF
[ansible]
name=ansible
baseurl=file://$(pwd)/
gpgcheck=0
enabled=1
EOF
#安装python3.7
tar xvfz $(pwd)/python37.tar.gz -C /usr/local/
#安装ansible
yum install ansible -y
#验证ansible
ansible --version
#恢复系统源
cd /etc/yum.repos.d/
rename repo.bak repo *bak
cd -
cat >> /etc/ansible/hosts <<EOF
#示例:
#localhost ansible_ssh_host=127.0.0.1 ansible_ssh_port=22 ansible_ssh_user="root" ansible_python_interpreter=/usr/local/python37/bin/python
EOF
5.打包
tar cvfz /tmp/ansible.tar.gz /tmp/ansible
二、离线包安装(无网络的机器)
1.上传安装包
/tmp/ansible.tar.gz
2.解压安装包
cd /tmp/ && tar xvfz ansible.tar.gz
3.执行安装脚本
cd ansible && sh ./init.sh
4.验证
[root@localhost ansible-2.9.25-release]# ansible --version
ansible 2.9.25
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, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]