关于ansible的安装我想说
并不是所有时候通过yum都能安装ansile的,因为yum源的原因,会出现无可用包的情况。比方说你用的是亚马逊的源,你又不确定是否能用阿里的,这个时候就需要这样了:
首先安装gcc、gcc-c++包:yum install gcc gcc-c++
因为ansible基于python开发的,所以必须要有python环境。如果你的主机上已经存在python了就不说了,没有的话,你需要安装:
# wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
# tar xvzf Python-2.7.8.tgz
# cd Python-2.7.8
# ./configure --prefix=/usr/local
# make
# make install 我这里安装的是2.7的。
将python头文件拷贝到标准目录,以避免编译ansible时,找不到所需的头文件
# cd /usr/local/include/python2.7
# cp -a ./* /usr/local/include/
备份旧版本的python,并符号链接新版本的python
# cd /usr/bin
# mv python python.old
# ln -s /usr/local/bin/python2.7 /usr/local/bin/python
# rm -f /usr/bin/python && cp /usr/local/bin/python2.7 /usr/bin/python
修改yum脚本,使其指向旧版本的python,已避免其无法运行
# vim /usr/bin/yum
#!/usr/bin/python --> #!/usr/bin/python2.X
(这里要注意下,你在修改完毕后可能会发现你的yum不能使用了,会出现什么‘python -h’这样的字眼,因为你将yum指向了python2.X的版本,好像yum只用于2.6及之前的版本,所以你在装怕python的时候尽量装2.6之前的。)
(1)接下来就是各种模块的安装了,首先是setuptools模块
# wget https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz --no-check-certificate
# tar xvzf setuptools-7.0.tar.gz
# cd setuptools-7.0
# python setup.py install (setuptools是python的工具,用来解决安装其他模块所需要的依赖关系)
如果安装过程中出现如下错误:Compression requires the (missing) zlib module
就安装 1、yum install zlib
2、yum install zlib-devel
再重新make python及make install python
(2)pycrypto模块安装
# wget https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz --no-check-certificate
# tar xvzf pycrypto-2.6.1.tar.gz
# cd pycrypto-2.6.1
# python setup.py install
(3)PyYAML模块安装
# wget http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz --no-check-certificate
# tar xvzf yaml-0.1.5.tar.gz
# cd yaml-0.1.5
# ./configure --prefix=/usr/local
# make
# make install
# wget https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz --no-check-certificate
# tar xvzf PyYAML-3.11.tar.gz
# cd PyYAML-3.11
# python setup.py install
(4)Jinja2模块安装
# wget https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.9.3.tar.gz --no-check-certificate
# tar xvzf MarkupSafe-0.9.3.tar.gz
# cd MarkupSafe-0.9.3
# python setup.py install
# wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz --no-check-certificate
# tar xvzf Jinja2-2.7.3.tar.gz
# cd Jinja2-2.7.3
# python setup.py install
(5)paramiko模块安装
wget https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz --no-check-certificate
# tar xvzf ecdsa-0.11.tar.gz
# cd ecdsa-0.11
# python setup.py install
# wget https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz --no-check-certificate
# tar xvzf paramiko-1.15.1.tar.gz
# cd paramiko-1.15.1
# python setup.py install
(6)simplejson模块安装
wget https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz --no-check-certificate
# tar xvzf simplejson-3.6.5.tar.gz
# cd simplejson-3.6.5
# python setup.py install
(7)ansible安装
# wget https://github.com/ansible/ansible/archive/v1.7.2.tar.gz --no-check-certificate
# tar xvzf ansible-1.7.2.tar.gz
# cd ansible-1.7.2
# python setup.py install
接下来将安装好的ansible的hosts文件拷到etc下,/etc/ansible/hosts。
下面这个不一定用得到,但是我用上了,
# wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz
tar -zxvf sshpass-1.06.tar.gz
cd sshpass-1.06
./configure
make
make install