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在虛擬環境下安裝加載完成