Ansible2.5 + Python3.6 安装部署
安装 python3.6.5 和 virtualenv 工具
安装python3.6.5
[root@ansible ~]# wget http://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
[root@ansible ~]# tar -xf Python-3.6.5.tar.xz -C /usr/local/src/
[root@ansible ~]# cd /usr/local/src/Python-3.6.5/
[root@ansible ~]# cd /usr/local/src/Python-3.6.5/
[root@ansible Python-3.6.5]# ./configure --prefix=/usr/local/ --with-ensurepip=install --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
#这里可能会报错
configure: error: in `/usr/local/src/Python-3.6.5':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
# 根据报错信息,需要安装GCC套件
[root@ansible Python-3.6.5]# yum install -y gcc
# 然后再次执行编译操作,完事执行安装
[root@ansible Python-3.6.5]# make && make altinstall
# 然而又报错了
....
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [altinstall] Error 1
# 提示很明显了直接执行
[root@ansible Python-3.6.5]# yum install zlib*
# 然后再次运行安装命令即可
[root@ansible Python-3.6.5]# make && make altinstall
# 当看到
.....
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.3 setuptools-39.0.1
# 表明安装成功
安装 virtualenv
[root@ansible bin]# pwd
/usr/local/bin
[root@ansible bin]# ./pip --trusted-host pypi.python.org install virtualenv
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting virtualenv
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/virtualenv/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/virtualenv/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/virtualenv/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/virtualenv/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/virtualenv/
Could not fetch URL https://pypi.python.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
Could not find a version that satisfies the requirement virtualenv (from versions: )
No matching distribution found for virtualenv
# 根据第一行报错提示
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
# 需要安装 openssl 相关软件包
[root@ansible bin]# yum install -y openssl*
# 除此之外,卸载掉 python2.7 安装的 pip 防止干扰
[root@ansible bin]# python -m pip uninstall pip
Uninstalling pip-18.1:
Would remove:
/usr/bin/pip
/usr/bin/pip2
/usr/bin/pip2.7
/usr/lib/python2.7/site-packages/pip-18.1.dist-info/*
/usr/lib/python2.7/site-packages/pip/*
Proceed (y/n)? y
Successfully uninstalled pip-18.1
# 然后回到解压包里,重新运行编译安装过程
[root@ansible Python-3.6.5]# ./configure --prefix=/usr/local/ --with-ensurepip=install --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
[root@ansible Python-3.6.5]# make && make altinstall
.......
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: pip in /usr/local/lib/python3.6/site-packages
[root@ansible Python-3.6.5]# cd ../../bin/
[root@ansible bin]# ll
total 68
-rwxr-xr-x. 1 root root 101 Jan 7 11:42 2to3-3.6
-rwxr-xr-x. 1 root root 242 Jan 7 11:00 easy_install-3.6
-rwxr-xr-x. 1 root root 99 Jan 7 11:42 idle3.6
lrwxrwxrwx. 1 root root 21 Jan 7 11:03 pip -> /usr/local/bin/pip3.6
-rwxr-xr-x. 1 root root 214 Jan 7 11:00 pip3.6
-rwxr-xr-x. 1 root root 84 Jan 7 11:42 pydoc3.6
-rwxr-xr-x. 2 root root 17712 Jan 7 11:41 python3.6
-rwxr-xr-x. 2 root root 17712 Jan 7 11:41 python3.6m
-rwxr-xr-x. 1 root root 3109 Jan 7 11:42 python3.6m-config
-rwxr-xr-x. 1 root root 441 Jan 7 11:42 pyvenv-3.6
[root@ansible bin]# ln -s /usr/local/bin/pip3.6 /usr/local/bin/pip
# 再次使用 pip 安装 virtualenv
[root@ansible bin]# pip install virtualenv
Collecting virtualenv
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/6a/d1/e0d142ce7b8a5c76adbfad01d853bca84c7c0240e35577498e20bc2ade7d/virtualenv-16.2.0-py2.py3-none-any.whl (1.9MB)
100% |████████████████████████████████| 1.9MB 64kB/s
Requirement already satisfied: setuptools>=18.0.0 in /usr/local/lib/python3.6/site-packages (from virtualenv)
Installing collected packages: virtualenv
Successfully installed virtualenv-16.2.0
You are using pip version 9.0.3, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# 安装成功
创建 ansible 账户并安装 python3.6.5 版本 virtualenv 实例
[root@ansible ~]# useradd deploy && su - deploy
[deploy@ansible ~]$ virtualenv -p /usr/local/bin/python3.6 .py3-a2.5-env
Already using interpreter /usr/local/bin/python3.6
Using base prefix '/usr/local'
New python executable in /home/deploy/.py3-a2.5-env/bin/python3.6
Also creating executable in /home/deploy/.py3-a2.5-env/bin/python
Installing setuptools, pip, wheel...
done.
[deploy@ansible ~]$
Git 源码安装 ansible2.5
# 首先使用root账户确保git nss curl命令已经安装
[root@ansible ~]# yum install -y git nss curl
# 然后切到deploy用户,进入之前创建的.py3-a2.5-env目录下
[deploy@ansible ~]$ cd /home/deploy/.py3-a2.5-env/
[deploy@ansible .py3-a2.5-env]$ git clone https://github.com/ansible/ansible.git
加载 python3.6.5 virtualenv 环境
[deploy@ansible .py3-a2.5-env]$ source /home/deploy/.py3-a2.5-env/bin/activate
(.py3-a2.5-env) [deploy@ansible .py3-a2.5-env]$
安装 ansible 依赖包
# 安装依赖包
(.py3-a2.5-env) [deploy@ansible .py3-a2.5-env]$ pip install paramiko PyYAML jinja2
(.py3-a2.5-env) [deploy@ansible .py3-a2.5-env]$ ll
total 8
drwxrwxr-x. 14 deploy deploy 4096 Jan 7 13:31 ansible
drwxrwxr-x. 2 deploy deploy 4096 Jan 7 11:52 bin
drwxrwxr-x. 2 deploy deploy 24 Jan 7 11:52 include
drwxrwxr-x. 3 deploy deploy 23 Jan 7 11:52 lib
(.py3-a2.5-env) [deploy@ansible .py3-a2.5-env]$ pwd
/home/deploy/.py3-a2.5-env
在 python3.6.5 虚拟环境下加载 ansible2.5
# 确认ansible源码包在.py3-a2.5-env目录下
# 进入ansible目录
(.py3-a2.5-env) [deploy@ansible .py3-a2.5-env]$ cd ansible/
(.py3-a2.5-env) [deploy@ansible ansible]$ pwd
/home/deploy/.py3-a2.5-env/ansible
(.py3-a2.5-env) [deploy@ansible ansible]$ git checkout stable-2.5 #将ansible切换到2.5版本
Branch stable-2.5 set up to track remote branch stable-2.5 from origin.
Switched to a new branch 'stable-2.5'
(.py3-a2.5-env) [deploy@ansible ansible]$ source /home/deploy/.py3-a2.5-env/ansible/hacking/env-setup -q #在此虚拟环境下加载ansible2.5版本
验证 ansible 版本
(.py3-a2.5-env) [deploy@ansible ansible]$ ansible --version
ansible 2.5.14 (stable-2.5 6548b7a558) last updated 2019/01/07 13:56:01 (GMT +800)
config file = None
configured module search path = ['/home/deploy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/deploy/.py3-a2.5-env/ansible/lib/ansible
executable location = /home/deploy/.py3-a2.5-env/ansible/bin/ansible
python version = 3.6.5 (default, Jan 7 2019, 11:40:52) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
# 至此ansible2.5在虚拟环境下安装加载完成