前面的文档介绍了如何用pip2.6安装Ansible,但是pip2.6是基于python2.6安装的,而python2.6版本有点老。所以而已用python2.7安装Ansible。
其实python2.7安装Ansible和python2.6安装过程基本上是一样的,只不过在安装Ansible所需要的模块和Ansible时,需要用pip2.7来安装。
安装过程如下:
1、安装python2.7
安装python2.7前的准备
1
2
3
|
yum -y
install
readline readline-devel
yum -y
install
zlib-devel
yum -y
install
openssl openssl-devel
|
安装gcc编译工具
1
|
yum -y
install
gcc
|
下载python2.7安装包
下载地址: www.python.org
1
2
3
4
5
6
|
yum -y
install
xz
tar
Jxf Python-2.7.11.
tar
.xz
cd
Python-2.7.11
mkdir
/usr/local/python27
.
/configure
--prefix=
/usr/local/python27
make
&&
make
install
|
创建软连接
1
|
ln
-s
/usr/local/python27/bin/python2
.7
/usr/bin/python2
.7
|
2、安装pip2.7
安装setuptools
下载地址:https://pypi.python.org/pypi?%3Aaction=search&term=setuptools&submit=search
安装:
1
2
3
|
tar
zxf setuptools-19.6.2.
tar
.gz
cd
setuptools-19.6.2
python2.7 setup.py
install
|
安装pip
下载地址:https://pypi.python.org/pypi/pip/
安装:
1
2
3
|
tar
zxf pip-8.1.0.
tar
.gz
cd
pip-8.1.0
python2.7 setup.py
install
|
创建软连接
1
|
ln
-s
/usr/local/python27/bin/pip2
.7
/usr/bin/pip2
.7
|
3、安装Ansible
安装依赖包
1
2
|
yum -y
install
libffi libffi-devel
yum -y
install
gcc gcc-c++ python-devel python-simplejson
|
安装Ansible需要的python模块
1
|
pip2.7
install
paramiko PyYAML Jinja2 httplib2 six
|
安装Ansible
1
|
pip
install
ansible
|
安装完成后,ansible的执行文件在python2.7的bin目录下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[root@localhost bin]
# cd /usr/local/python27/bin/
[root@localhost bin]
# ll
total 6240
-rwxr-xr-x. 1 root root 110 Jun 15 17:31 2to3
-rwxr-xr-x. 1 root root 4203 Jun 15 17:48 ansible
-rwxr-xr-x. 1 root root 4203 Jun 15 17:48 ansible-console
-rwxr-xr-x. 1 root root 4203 Jun 15 17:48 ansible-doc
-rwxr-xr-x. 1 root root 4203 Jun 15 17:48 ansible-galaxy
-rwxr-xr-x. 1 root root 4203 Jun 15 17:48 ansible-playbook
-rwxr-xr-x. 1 root root 4203 Jun 15 17:48 ansible-pull
-rwxr-xr-x. 1 root root 4203 Jun 15 17:48 ansible-vault
-rwxr-xr-x. 1 root root 326 Jun 15 17:41 easy_install
-rwxr-xr-x. 1 root root 334 Jun 15 17:41 easy_install-2.7
-rwxr-xr-x. 1 root root 108 Jun 15 17:31 idle
-rwxr-xr-x. 1 root root 284 Jun 15 17:42 pip
-rwxr-xr-x. 1 root root 286 Jun 15 17:42 pip2
-rwxr-xr-x. 1 root root 290 Jun 15 17:42 pip2.7
-rwxr-xr-x. 1 root root 93 Jun 15 17:31 pydoc
lrwxrwxrwx. 1 root root 7 Jun 15 17:33 python -> python2
lrwxrwxrwx. 1 root root 9 Jun 15 17:33 python2 -> python2.7
-rwxr-xr-x. 1 root root 6271354 Jun 15 17:31 python2.7
-rwxr-xr-x. 1 root root 1696 Jun 15 17:33 python2.7-config
lrwxrwxrwx. 1 root root 16 Jun 15 17:33 python2-config -> python2.7-config
lrwxrwxrwx. 1 root root 14 Jun 15 17:33 python-config -> python2-config
-rwxr-xr-x. 1 root root 18556 Jun 15 17:31 smtpd.py
|
编辑/etc/profile文件,加入以下配置
1
2
|
export
ANSIBLE_HOME=
/usr/local/python27
export
PATH=$PATH:$ANSIBLE_HOME
/bin
|
1
2
3
4
|
[root@localhost bin]
# ansible --version
ansible 2.1.0.0
config
file
=
configured module search path = Default w
/o
overrides
|
本文转自 曾哥最爱 51CTO博客,原文链接:http://blog.51cto.com/zengestudy/1789854,如需转载请自行联系原作者