Linux 下编译安装 ansible (二) - Python3
前几天使用了 Python2
来编译安装 Ansible
,发现 Ansible
已经渐渐不再支持 Python2
,这篇文章将使用目前最新版本的模块来安装。
Python Version:
Python 3.9.1
setuptools Version:
setuptools-51.0.0
pycparser Version:
pycparser-2.20
cffi Version:
cffi-1.14.4
cryptography Version:
cryptography-3.3.1
PyYAML Version:
PyYAML-5.3.1
MarkupSafe Version:
MarkupSafe-1.1.1
Jinja2 Version:
Jinja2-2.11.2
ansible Version:
ansible 2.9.13
一、升级 Python 版本
1.安装所需依赖
$ sudo yum -y install libffi-devel openssl-devel python-devel zilb-devel unzip
2.升级至 Python3
$ wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
$ tar xf Python-3.9.1.tgz
$ cd Python-3.9.1.tgz
$ ./configure
$ sudo make && make install
$ python3 --version
Python 3.9.1
二、安装 ansible 所以模块
注意:如果地址失效,可自行搜索下载 https://pypi.org/
1.setuptools
$ wget https://files.pythonhosted.org/packages/12/e1/b9a2926a3c5a3fb055b8f85052f5baa890106a0e21b64a977c10affea751/setuptools-51.0.0.zip
$ unzip setuptools-51.0.0.zip
$ cd setuptools-51.0.0
$ python3 setup.py install
pyhontModuleNotFoundError: No module named '_ctypes'
#如果遇到此报错是没有 libffi-devel 这个依赖包导致,yum 安装后还需要重新编译安装一遍 Python
2.pycparser
-> cffi
所依赖
error: Could not find suitable distribution for Requirement.parse('pycparser')
#需要先安装 pycparser,cffi 所依赖
$ wget https://files.pythonhosted.org/packages/0f/86/e19659527668d70be91d0369aeaa055b4eb396b0f387a4f92293a20035bd/pycparser-2.20.tar.gz
$ tar xf pycparser-2.20.tar.gz
$ cd pycparser-2.20
$ python3 setup.py install
3.cffi
-> cryptography
所依赖
ERROR: Could not find a version that satisfies the requirement cffi>=1.12 (from versions: none)
ERROR: No matching distribution found for cffi>=1.12
#需要先安装 cffi,不然会有以下报错
$ wget https://files.pythonhosted.org/packages/66/6a/98e023b3d11537a5521902ac6b50db470c826c682be6a8c661549cb7717a/cffi-1.14.4.tar.gz
$ tar xf cffi-1.14.4.tar.gz
$ cd cffi-1.14.4
$ python3 setup.py install
4.cryptography
error: Could not find suitable distribution for Requirement.parse('cryptography')
#未安装会有此报错
$ wget https://files.pythonhosted.org/packages/b7/82/f7a4ddc1af185936c1e4fa000942ffa8fb2d98cff26b75afa7b3c63391c4/cryptography-3.3.1.tar.gz
$ tar xf cryptography-3.3.1.tar.gz
$ cd cryptography-3.3.1
$ python3 setup.py install
关系是这样的 pycparser
-> cffi
-> cryptography
5.PyYAML
$ wget https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz
$ tar xf PyYAML-5.3.1.tar.gz
$ cd PyYAML-5.3.1
$ python3 setup.py install
6.MarkupSafe
-> Jinja2
所依赖
$ wget https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
$ tar xf MarkupSafe-1.1.1.tar.gz
$ cd MarkupSafe-1.1.1
$ python3 setup.py install
7.Jinja2
$ wget https://files.pythonhosted.org/packages/64/a7/45e11eebf2f15bf987c3bc11d37dcc838d9dc81250e67e4c5968f6008b6c/Jinja2-2.11.2.tar.gz
$ tar xf Jinja2-2.11.2.tar.gz
$ cd Jinja2-2.11.2
$ python3 setup.py install
不然会有以下报错:
ansible 2.9.13 requires jinja2, which is not installed.
ansible 2.9.13 requires PyYAML, which is not installed.
8.编译安装 ansible
$ wget https://releases.ansible.com/ansible/ansible-latest.tar.gz
$ tar xf ansible-latest.tar.gz
$ cd ansible-2.9.13
$ python3 setup.py install
三、验证
1.完善配置文件及验证
$ cp -rp examples/* /etc/ansible/
$ ansible --version
ansible 2.9.13
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.9/site-packages/ansible-2.9.13-py3.9.egg/ansible
executable location = /usr/local/bin/ansible
python version = 3.9.1 (default, Dec 21 2020, 10:18:09) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
2.不拷贝的话会出现以下情况
$ ansible --version
ansible 2.9.13
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible-2.9.13-py3.9.egg/ansible
executable location = /usr/local/bin/ansible
python version = 3.9.1 (default, Dec 21 2020, 10:18:09) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Over~
版权协议须知!
本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
1423 0 2020-12-20
博主卡片
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。
现在时间 2024-12-28
今日天气
随机推荐
站点统计
- 文章总数:241篇
- 分类总数:29个
- 评论总数:12条
- 本站总访问量 353805 次
@xiaozi 最后的分享的镜像下载地址打不开 服务器没有开机吗?
@yuanyuan 为什么我的4b安装centos7.9 插上tf卡 显示不兼...
@Wong arrhenius 牛比
@MakerFace 厉害了!
@TongSir 老哥 更新下我的友链链接 https://blog.ton...