基於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