ansible离线安装

写给那些跟我一样,公司无法上外网的人,希望通过本文让你我再次面对类似问题时不在手足无措、不在大脑空白!

为什么你的公司不让连外网?

我身边有个技术大咖,他跟我讲了在前公司任职期内的遇到一件事情,让我理解了企业在技术与安全之间的艰难抉择。
这家互联网公司,原本很自由、很舒适,开发没有任何限制。直到有一天,财务的电脑被非法入侵,致使财务系统的各种文件、数据被锁死,还被电话勒索。眼看过几天就要报税,公司却乱成一锅粥,只能拿钱消灾。从那以后,老板就组起了局域网,哪些自由上网的日子已经不去不复返了,大咖也离职了。

离线安装的难点

通常,Python项目根目录下中都会有一个 requirements.txt 文件,用于记录项目dependencies 的依赖关系,但不能作为部署安装包,它既没有说明版本号,又没提供这几个包的依赖包。
所以,离线安装软件,最窘迫的地方是你不知道它依赖了多少包,也不知道它依赖了什么包,更不知道这些包的版本号。针对这种依赖包多而散、版本不明确的离线软件安装,你要么网页搜索看看前人有没有类似诉求,要么根据错误提示,一个个安装执行依赖包。
ansible项目的requirements.txt【github ansible

# Note: this requirements.txt file is used to specify what dependencies are
# needed to make the package run rather than for deployment of a tested set of
# packages.  Thus, this should be the loosest set possible (only required
# packages, not optional ones, and with the widest range of versions that could
# be suitable)
jinja2
PyYAML
cryptography
packaging

使用 pip/pip3 freeze 命令查看已安装ansible的部署依赖包:

suse12-appm-ora12c-db01:~ # pip3 freeze ansible
	aniso8601==8.0.0
	ansible==2.9.10
	certifi==2020.6.20
	cffi==1.14.0
	chardet==3.0.4
	click==7.1.2
	cryptography==2.9.2
	Flask==1.1.2
	Flask-RESTful==0.3.8
	idna==2.10
	itsdangerous==1.1.0
	Jinja2==2.11.2
	MarkupSafe==1.1.1
	pycparser==2.20
	pytz==2020.1
	PyYAML==5.3.1
	requests==2.24.0
	six==1.15.0
	urllib3==1.25.9
	Werkzeug==1.0.1

离线安装的通用套路

解决离线安装依赖包多而散的方式通常有两种:

  1. 有人提供现成的依赖包下载链接。优点是多快好省,缺点是依赖包与ansible的版本有强耦合关系,不同版本的ansible要求的不同版本依赖包,这里提供百度云永久下载链接【ansible2.9.10依赖包 ,提取码:0gqj】
  2. 根据安装报错提示,一遍遍下载、传输、安装。为解决因ansible版本导致的个别依赖包不匹配问题,可以根据错误提示,去pypi官网下载,再上传到离线机器进行安装。

如果你选择方式1,需依次安装python3.6、cryptography、ansible,若需结合flask框架进行二次开发,再依次安装requests、Flask,下面给出参考

#编译安装python3
./configure
make
make install(如zlib not available,到other目录下编译安装)
#安装cryptography、ansible,分别cd到根目录
pip3 install *
#安装requests、Flask,分别cd到根目录(不用Flask可不安装)
pip3 install *

卸载离线包

因为使用的pip安装,所以卸载是用 pip/pip3 uninstall xxx 即可。

[root@144 ansible2.9.10]# ansible --version
ansible 2.9.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.1 (default, Jul 27 2020, 17:46:31) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

[root@144 ~]# pip3 uninstall ansible

如果 pip uninstall 出现意外的话,利用 find 和 rm 命令,先查找再删除。

[root@144 ansible2.9.10]# find / -name ansible
/root/ansible
/usr/local/bin/ansible
/usr/local/lib/python3.6/site-packages/ansible_test/_data/injector/ansible
/usr/local/lib/python3.6/site-packages/ansible
/etc/ansible

遇见问题

编号问题解决
1Collecting enum34; python_version < “3” (from cryptography==2.9.2)安装python3,虽然ansible2.x支持python2,但cryptography却要求3。
2Fatal Python error: Py_Initialize: Unable to get the locale encoding,LookupError: unknown encoding: GB2312临时修改:export LC_ALL=zh_CN.utf-8。永久修改:vi /etc/profle 加一句export LC_ALL=zh_CN.utf-8
3Collecting enum34; python_version < “3” (from cryptography==2.9.2)安装python3,虽然ansible2.x支持python2,但cryptography却要求3。
4zlib not available编译安装zlib
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值