安装Python3
安装依赖
1
$ yum install zlib zlib-devel openssl-devel libffi-devel
下载介质
DownLoad
编辑./Modules/Setup取消ssl注释
1
2
3
4
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
编译安装
1
2
$ ./configure --prefix=/usr/local/python3
$ make && make install -j 4
添加环境变量
1
2
$ echo "export PATH=$PATH:/usr/local/python3/bin" >>/ etc / profile
$ source / etc / profile
查看版本
1
2
[root@h-luhx-254 packages]# python3 --version
Python 3.8.7
安装Ansible
下载python依赖包
MarkupSafe
Jinja2
six
pycparser
cffi
cryptography
PyYAML
pyparsing
packaging
setuptools
安装依赖包
1
2
3
4
5
6
7
8
9
10
$ pip3 install MarkupSafe - 1.1 . 1 - cp38 - cp38 - manylinux1_x86_64 . whl
$ pip3 install Jinja2 - 2.11 . 3 - py2 . py3 - none - any . whl
$ pip3 install six - 1.15 . 0 - py2 . py3 - none - any . whl
$ pip3 install pycparser - 2.20 - py2 . py3 - none - any . whl
$ pip3 install cffi - 1.14 . 4 - cp38 - cp38 - manylinux1_x86_64 . whl
$ pip3 install cryptography - 3.3 . 1 - cp36 - abi3 - manylinux2010_x86_64 . whl
$ pip3 install PyYAML - 5.4 . 1 - cp38 - cp38 - manylinux1_x86_64 . whl
$ pip3 install pyparsing - 2.4 . 7 - py2 . py3 - none - any . whl
$ pip3 install packaging - 20.9 - py2 . py3 - none - any . whl
$ pip3 install setuptools - 53.0 . 0 - py3 - none - any . whl
查看安装的包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[ root @ h - luhx - 254 ansible - 2.10 . 5 ] # pip3 list
Package Version
------------ -------
cffi 1.14 . 4
cryptography 3.3 . 1
Jinja2 2.11 . 3
MarkupSafe 1.1 . 1
packaging 20.9
pip 20.2 . 3
pycparser 2.20
pyparsing 2.4 . 7
PyYAML 5.4 . 1
setuptools 53.0 . 0
six 1.15 . 0
下载ansible
DownLoad
解压安装包
1
$ tar -xvf v2.10.5.tar.gz
安装ansible
1
2
$ cd ansible-2.10.5/
$ python3 setup.py install
安装出现如下错误
1
Ansible now needs setuptools in order to build . Install it using your package manager ( usually python - setuptools ) or via pip ( pip install setuptools ) .
查看setup.py的内容
1
2
3
4
5
6
7
8
9
10
try :
from setuptools import setup , find_packages
from setuptools . command . build_py import build_py as BuildPy
from setuptools . command . install_lib import install_lib as InstallLib
from setuptools . command . install_scripts import install_scripts as InstallScripts
except ImportError :
print ( "Ansible now needs setuptools in order to build. Install it using"
" your package manager (usually python-setuptools) or via pip (pip"
" install setuptools)." , file = sys . stderr )
sys . exit ( 1 )
尝试手动加载
1
2
3
4
5
6
[ root @ h - luhx - 254 Python - 3.8 . 7 ] # python3
Python 3.8 . 7 ( default , Feb 3 2021 , 20 : 53 : 47 )
[ GCC 4.8 . 5 20150623 ( Red Hat 4.8 . 5 - 44 )] on linux
Type "help" , "copyright" , "credits" or "license" for more information .
>>> from setuptools import setup , find_packages
ModuleNotFoundError : No module named '_ctypes'
Python3中有个内置模块叫ctypes,它是Python3的外部函数库模块,它提供兼容C语言的数据类型,并通过它调用Linux系统下的共享库(Shared library)。由于在CentOS7系统中没有安装外部函数库(libffi)的开发链接库软件包,因此我们需要手动安装并重新编译python
1
2
$ yum install libffi-devel -y
$ make && make install -j 4
查看ansible的版本
1
2
3
4
5
6
7
[root@h-luhx-254 ansible-2.10.5]# ansible --version
ansible 2.10.5
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/python3/lib/python3.8/site-packages/ansible_base-2.10.5-py3.8.egg/ansible
executable location = /usr/local/python3/bin/ansible
python version = 3.8.7 (default, Feb 3 2021, 20:53:47) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Licensed under CC BY-NC-SA 4.0