本文共 3812 字,大约阅读时间需要 12 分钟。
**安装的时候需要很多依赖 ,因为ansible是基于Python写出来的,所以需要先安装Python,Python版本>=2.6才能安装Ansible。
Yum install python*
Ansible的安装是依赖一些模块的,所以首先安装依赖模块再安装Ansible# tar -xvzf setuptools-7.0.tar.gz # cd setuptools-7.0 # python setup.py install
# tar -xvzf pycrypto-2.6.1.tar.gz # cd pycrypto-2.6.1 # python setup.py install
=)
# tar -xvzf yaml-0.1.5.tar.gz # cd yaml-0.1.5 # ./configure --prefix=/usr/local # make && make install
PyYAMAL依赖于yaml包所以需要先安装yaml
# tar -xvzf PyYAML-3.11.tar.gz # cd PyYAML-3.11 # python setup.py install
# tar -xvzf MarkupSafe-0.9.3.tar.gz # cd MarkupSafe-0.9.3 # python setup.py install
# tar -xvzf Jinja2-2.7.3.tar.gz # cd Jinja2-2.7.3 # python setup.py install
# tar -xvzf ecdsa-0.11.tar.gz # cd ecdsa-0.11 # python setup.py install
# tar -xvzf paramiko-1.15.1.tar.gz # cd paramiko-1.15.1 # python setup.py install
# tar -xvzf simplejson-3.6.5.tar.gz # cd simplejson-3.6.5 # python setup.py install
# tar -xvzf ansible-1.7.2.tar.gz # cd ansible-1.7.2 # python setup.py install
# 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
[root@localhost .ssh]# ansible all -m ping -Ksudo password: 192.168.1.21 | success >> { "changed": false, "ping": "pong"}[root@localhost .ssh]#
测试成功!
1.# python setup.py install2.libyaml is not found or a compiler error: forcing --without-libyaml3.(if libyaml is installed correctly, you may need to4.specify the option --include-dirs or uncomment and5.modify the parameter include_dirs in setup.cfg)6.running install_lib7.running install_egg_info8.Removing /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-info9.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· from ansible.runner import Runner· File "/usr/local/src/ansible-devel/lib/ansible/runner/__init__.py", line 62, in · from Crypto.Random import atfork· File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in · from Crypto.Random import _UserFriendlyRNG· File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in · from Crypto.Random.Fortuna import FortunaAccumulator· File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in · import FortunaGenerator· File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in · 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 · 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的版本
安装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
转载于:https://blog.51cto.com/9480860/2105243