码迷,mamicode.com
首页 > 其他好文 > 详细

基于Centos6.6(7.2)源码安装Ansible

时间:2018-04-19 14:00:03      阅读:453      评论:0      收藏:0      [点我收藏+]

标签:Ansible源码安装

基于Centos6.6(7.2)源码安装Ansible

**安装的时候需要很多依赖 ,因为ansible是基于Python写出来的,所以需要先安装Python,Python版本>=2.6才能安装Ansible。

1、安装python

Yum install python*
Ansible的安装是依赖一些模块的,所以首先安装依赖模块再安装Ansible

2、安装setuptools模块

https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz

#?tar?-xvzf?setuptools-7.0.tar.gz??
#?cd?setuptools-7.0??
#?python?setup.py?install??

3、安装pycrypto模块

https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz

#?tar?-xvzf?pycrypto-2.6.1.tar.gz??
#?cd?pycrypto-2.6.1??
#?python?setup.py?install??

4、安装PyYAML模块

http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz![](http://i2.51cto.com/images/blog/201804/19/9a6787245b7bcfb4d27f94590e958e56.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

#?tar?-xvzf?yaml-0.1.5.tar.gz??
#?cd?yaml-0.1.5??
#?./configure?--prefix=/usr/local??
#?make?&&?make?install??

PyYAMAL依赖于yaml包所以需要先安装yaml
https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz

#?tar?-xvzf?PyYAML-3.11.tar.gz??
#?cd?PyYAML-3.11??
#?python?setup.py?install??   

5、安装jinja2模块

https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.9.3.tar.gz

#?tar?-xvzf?MarkupSafe-0.9.3.tar.gz??
#?cd?MarkupSafe-0.9.3??
#?python?setup.py?install??

https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz

#?tar?-xvzf?Jinja2-2.7.3.tar.gz??
#?cd?Jinja2-2.7.3??
#?python?setup.py?install??

6、安装paramiko模块

https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz

#?tar?-xvzf?ecdsa-0.11.tar.gz??
#?cd?ecdsa-0.11??
#?python?setup.py?install??

https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz

#?tar?-xvzf?paramiko-1.15.1.tar.gz??
#?cd?paramiko-1.15.1??
#?python?setup.py?install??

7、安装simplejson模块(如果是Python2.版本的话可以忽略此模块的安装)

https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz

#?tar?-xvzf?simplejson-3.6.5.tar.gz??
#?cd?simplejson-3.6.5??
#?python?setup.py?install??

8、安装ansible模块

https://github.com/ansible/ansible/archive/v1.7.2.tar.gz

#?tar?-xvzf?ansible-1.7.2.tar.gz??
#?cd?ansible-1.7.2??
#?python?setup.py?install??

9、配置Ansible

# mkdir /etc/ansible
#cp /home/cjx/ansible/examples/hosts(ansible)  /etc/ansible/

修改配置文件将一下三个配置去注释

host_key_checking = False    是否检查主机密钥 (跳过ssh 首次连接提示验证部分,False表示跳过)
log_path = /var/log/ansible.log     日志文件存放路径
accelerate_multi_key = yes   开启加速

在hosts上添加节点机器

[haha]
192.168.1.21

10、测试Ansible

[root@localhost .ssh]# ansible all -m ping -K
sudo password: 
192.168.1.21 | success >> {
    "changed": false, 
    "ping": "pong"
}

[root@localhost .ssh]# 

测试成功!

11、Ansible出错解决方案

出错1:安装yaml的时候报错

1.# python setup.py install
2.libyaml is not found or a compiler error: forcing --without-libyaml
3.(if libyaml is installed correctly, you may need to
4.specify the option --include-dirs or uncomment and
5.modify the parameter include_dirs in setup.cfg)
6.running install_lib
7.running install_egg_info
8.Removing /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-info
9.Writing /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-info

如果继续安装的话在安装Ansible会报错:

 Traceback (most recent call last):
·  File "/usr/local/src/ansible-devel/bin/ansible", line 36, in <module>
·  from ansible.runner import Runner
·  File "/usr/local/src/ansible-devel/lib/ansible/runner/__init__.py", line 62, in <module>
·  from Crypto.Random import atfork
·  File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in <module>
·  from Crypto.Random import _UserFriendlyRNG
·  File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
·  from Crypto.Random.Fortuna import FortunaAccumulator
·  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
·  import FortunaGenerator
·  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in <module>
·  from Crypto.Util.number import ceil_shift, exact_log2, exact_div
·  File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
·  if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
·  AttributeError: ‘module‘ object has no attribute ‘HAVE_DECL_MPZ_POWM_SEC‘

根据报错提示可以知道主要是因为pycrypto包依赖的GMP版本不对,打开/usr/lib64/python2.6/site-packages/Crypto/Util/number.py可以看到56行的注释要求你libgmp版本在V5以上,而系统现在的版本是4.1.4,可以把这行注释掉,永久解决的话是更新升级libgmp的版本

出错2:安装 pycrypto的时候会报错

安装Python的时候必须要安装python-devel否则在安装 pycrypto的时候会报错,报错如下图所示:
技术分享图片

(error: Setup script exited with error: command ‘gcc‘ failed with exit status 1)

运行Ansible会报如下错误:

pkg_resources.DistributionNotFound: pycrypto>=2.6

技术分享图片
解决:把Python的依赖包python-devel-2.6.6-66.el6_8.x86_64安装上去即可

# yum install python-devel

基于Centos6.6(7.2)源码安装Ansible

标签:Ansible源码安装

原文地址:http://blog.51cto.com/9480860/2105243

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!