1、测试环境描述
系统 SuSE 11 sp2
因为是生产环境无法访问外网,所以搭建环境都是离线环境下源码安装的。
软件包:
Python-2.7.11.tar.xz
setuptools-7.0.tar.gz
pycrypto-2.6.1.tar.gz
yaml-0.1.4.tar.gz
PyYAML-3.11.tar.gz
MarkupSafe-0.9.3.tar.gz
Jinja2-2.7.3.tar.gz
ecdsa-0.11.tar.gz
paramiko-1.15.1.tar.gz
simplejson-3.6.5.tar.gz
ansible-1.7.2.tar.gz
如果顺利的话一次编译上边的源码包就可以完成环境的搭建,但是我的环境中在刚开始编译python的时候就出现了问题
2、问题描述及解决过程
ansible需要python的支持,我们的环境中都是python2.6的,网上看好多文章都说到使用python2.7版本会比较好,在之后依赖性的问题会比较少,说做就做,结果在编译python的过程中折腾了老半天,下面详细记录遇到的问题。
环境原本的python环境
server:/ansibletest # python
Python 2.6 (r26:66714, May 6 2011, 15:10:21)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
备份python脚本
server:/ansibletest # mv /usr/bin/python /usr/bin/python.bak
server:/ansibletest # xz -d Python-2.7.11.tar.xz
(如果环境中没有xz命令说明还需要编译xz工具)
server:/ansibletest # tar -xf Python-2.7.11.tar
server:/ansibletest # mkdir src
server:/ansibletest/Python-2.7.11 # ./configure --prefix=/ansibletest/src/python27
server:/ansibletest/Python-2.7.11 # make
make出错
linux-3qo7:/ansibletest/Python-2.7.11 # make
Failed to build these modules:
_curses _curses_panel _hashlib
_ssl
出现上边的错误如果不解决的话之后在编译ecdsa-0.11.tar.gz 的时候就会出现下面的错误
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
.......略过信息
ValueError: unsupported hash type sha512
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from ecdsa.six import print_
File "/ansibletest/ecdsa-0.11/ecdsa/__init__.py", line 3, in <module>
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError
File "/ansibletest/ecdsa-0.11/ecdsa/keys.py", line 5, in <module>
from . import rfc6979
File "/ansibletest/ecdsa-0.11/ecdsa/rfc6979.py", line 14, in <module>
from .util import number_to_string, number_to_string_crop
File "/ansibletest/ecdsa-0.11/ecdsa/util.py", line 6, in <module>
from hashlib import sha256
ImportError: cannot import name sha256
经过网上的查找,定位到缺少_curses和_curses_panel是因为缺少ncurses-devel的包,而缺少_hashlib 和_ssl我则参考下面链接里的文章 。
http://blog.csdn.net/chary8088/article/details/22891357
处理过程:
根据我的另一篇文章你可以在本地windows系统搭建一个yum源
链接:http://xiaoxiaozhou.blog.51cto.com/4681537/1888713
环境基础安装组件:
rpm -qa | grep ncurses
libncurses5-32bit-5.6-90.55
libncurses5-5.6-90.55
yast2-ncurses-2.17.20-0.5.103
libncurses6-5.6-90.55
ncurses-utils-5.6-90.55
yast2-ncurses-pkg-2.17.19-0.5.100
安装ncurses-devel
# zypper install ncurses-devel
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following NEW packages are going to be installed:
ncurses-devel tack
2 new packages to install.
Overall download size: 3.2 MiB. After the operation, additional 22.7 MiB will be used.
Continue? [y/n/?] (y): y
Retrieving package tack-5.6-90.55.x86_64 (1/2), 79.0 KiB (170.0 KiB unpacked)
Retrieving: tack-5.6-90.55.x86_64.rpm [done]
Retrieving package ncurses-devel-5.6-90.55.x86_64 (2/2), 3.1 MiB (22.5 MiB unpacked)
Retrieving: ncurses-devel-5.6-90.55.x86_64.rpm [done]
Installing: tack-5.6-90.55 [done]
Installing: ncurses-devel-5.6-90.55 [done]
编译openssl-1.0.1h.tar.gz
解压
server:/ansibletest # tar -zxf openssl-1.0.1h.tar.gz
编译
server:/ansibletest/openssl-1.0.1h # ./config --prefix=/ansibletest/usr/local/openssl
server:/ansibletest/openssl-1.0.1h # make && make install
server:/ansibletest # mkdir -p usr/local
server:/ansibletest/usr/local # ln -s openssl ssl
server:/ansibletest/usr/local # ln -s openssl /usr/local/ssl
server:/ansibletest/usr/local # vi /etc/ld.so.conf
/home/was_wcm/ansible/usr/local/openssl/lib
server:/ansibletest/usr/local # ldconfig
server:/ansibletest/usr/local # vi /etc/profile
export OPENSSL=/home/was_wcm/ansible/usr/local/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
server:/ansibletest/usr/local # source /etc/profile
server:/ansibletest/usr/local # ldd /home/was_wcm/ansible/usr/local/openssl/bin/openssl
linux-vdso.so.1 => (0x00007fff5f6ed000)
libssl.so.1.0.0 => /home/was_wcm/ansible/usr/local/openssl/lib/libssl.so.1.0.0 (0x00007fa9d7179000)
libcrypto.so.1.0.0 => /home/was_wcm/ansible/usr/local/openssl/lib/libcrypto.so.1.0.0 (0x00007fa9d6d9f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fa9d6b6a000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa9d67f6000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa9d73e6000)
再次编译python
server:/ansibletest/Python-2.7.11 # make
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
_tkinter bsddb185 bz2
dbm dl gdbm
p_w_picpathop readline sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
running build_scripts
server:/ansibletest/Python-2.7.11 # make install
server:/ansibletest/Python-2.7.11 # ln -s /ansibletest/src/python27/bin/python /usr/bin/python
server:/ansibletest/Python-2.7.11 # python
Python 2.7.11 (default, Oct 12 2016, 17:03:57)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/etc/pythonstart", line 7, in <module>
import readline
ImportError: No module named readline
>>>
(缺少readline模块的问题姑且不论,因为对于ansible的环境来说无关紧要)
因为编译ansible需要很多依赖环境,依赖环境的编译还有着一定的先后顺序,因为它们之间也存在依赖关系,下面开始编译环境。
3、开始编译安装ansible环境
编译setuptools
server:/ansibletest # tar zxf setuptools-7.0.tar.gz
server:/ansibletest # cd setuptools-7.0/
server:/ansibletest/setuptools-7.0 # python setup.py install
编译pycrypto
server:/ansibletest # tar zxf pycrypto-2.6.1.tar.gz
server:/ansibletest # cd pycrypto-2.6.1/
server:/ansibletest/pycrypto-2.6.1 # python setup.py install
编译yaml
server:/ansibletest # tar zxf yaml-0.1.4.tar.gz
server:/ansibletest # cd yaml-0.1.4/
server:/ansibletest/yaml-0.1.4 # ./configure --prefix=/ansibletest/usr/local/yaml
server:/ansibletest/yaml-0.1.4 # make
server:/ansibletest/yaml-0.1.4 # make install
编译PyYAML
server:/ansibletest # tar zxf PyYAML-3.11.tar.gz
server:/ansibletest # cd PyYAML-3.11/
server:/ansibletest/PyYAML-3.11 # python setup.py install
编译MarkupSafe
server:/ansibletest # tar zxf MarkupSafe-0.9.3.tar.gz
server:/ansibletest # cd MarkupSafe-0.9.3/
server:/ansibletest/MarkupSafe-0.9.3 # python setup.py install
编译Jinja2
server:/ansibletest # tar zxf Jinja2-2.7.3.tar.gz
server:/ansibletest # cd Jinja2-2.7.3/
server:/ansibletest/Jinja2-2.7.3 # python setup.py install
编译ecdsa
server:/ansibletest # tar zxf ecdsa-0.11.tar.gz
server:/ansibletest # cd ecdsa-0.11/
server:/ansibletest/ecdsa-0.11 # python setup.py install
server:/ansibletest/Python-2.7.11 # make
编译paramiko
server:/ansibletest # tar xvzf paramiko-1.15.1.tar.gz
server:/ansibletest # cd paramiko-1.15.1
server:/ansibletest # pythonsetup.py install
编译simplejson
server:/ansibletest # tar xvzf simplejson-3.6.5.tar.gz
server:/ansibletest # cdsimplejson-3.6.5
server:/ansibletest # pythonsetup.py install
编译ansible
server:/ansibletest # tar xvzf ansible-1.7.2.tar.gz
server:/ansibletest # cd ansible-1.7.2/
server:/ansibletest/ansible-1.7.2 # python setup.py install
至此一个完整的ansible服务端算是配置完成
一个小小的验证
配置客户端IP
server:~ # cat /etc/ansible/hosts
[slave]
192.168.1.101
server:/ansibletest/ansible-1.7.2 # ./bin/ansible all -m ping --ask-pass
SSH password:
paramiko: The authenticity of host '192.168.1.101' can't be established.
The ssh-rsa key fingerprint is 21e1cca2719628f4859afa0b1ea805ee.
Are you sure you want to continue connecting (yes/no)?
(all是对所有分组的进行批处理)
转载于:https://blog.51cto.com/xiaoxiaozhou/1867854