解决Ansible安装依赖问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决Ansible安装依赖问题相关的知识,希望对你有一定的参考价值。

由于每台机器的环境都不尽相同,存在某些机器的yum源太小或者所带软件版本太低或缺失等问题,所以在安装软件时也可能会产生不同的依赖报错。下面我就以安装ansible时自身遇到过的依赖问题解决方法作介绍,只介绍解决依赖部分内容,安装ansible详细过程另请自行百度。
一、 使用ansible --version
技术图片

Ansible并未安装完成,存在依赖问题。

附报错内容:
ERROR! Unexpected Exception, this is probably a bug: (cryptography 1.3.1 (/usr/lib64/python2.7/site-packages), Requirement.parse(‘cryptography>=1.5‘))
the full traceback was:

Traceback (most recent call last):
File "/usr/bin/ansible", line 97, in <module>
mycli = getattr(import("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
File "/usr/lib/python2.7/site-packages/ansible/cli/init.py", line 38, in <module>
from ansible.inventory.manager import InventoryManager
File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py", line 33, in <module>
from ansible.plugins.loader import inventory_loader
File "/usr/lib/python2.7/site-packages/ansible/plugins/loader.py", line 22, in <module>
from ansible.parsing.utils.yaml import from_yaml
File "/usr/lib/python2.7/site-packages/ansible/parsing/utils/yaml.py", line 17, in <module>
from ansible.parsing.yaml.loader import AnsibleLoader
File "/usr/lib/python2.7/site-packages/ansible/parsing/yaml/loader.py", line 30, in <module>
from ansible.parsing.yaml.constructor import AnsibleConstructor
File "/usr/lib/python2.7/site-packages/ansible/parsing/yaml/constructor.py", line 29, in <module>
from ansible.parsing.vault import VaultLib
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/init.py", line 45, in <module>
from cryptography.hazmat.backends import default_backend
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/init.py", line 7, in <module>
import pkg_resources
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 3011, in <module>
parse_requirements(requires), Environment()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 630, in resolve
raise VersionConflict(dist,req) # XXX put more info here
VersionConflict: (cryptography 1.3.1 (/usr/lib64/python2.7/site-packages), Requirement.parse(‘cryptography>=1.5‘))

估计是cryptography该模块的问题(版本太低)。

  1. 安装cryptography前先安装setuptools
    技术图片
    这里Setuptools版本需要大于等于18.5.
    技术图片

  2. 解压安装
    技术图片
    #python setup.py build
    #python setup.py install

  3. 安装cffi(在安装cryptography之前报错,应该先安装cffi)
    [root@zabbix-server cryptography-2.8]# python setup.py install
    Download error on https://pypi.python.org/simple/cffi/: [Errno -2] Name or service not known -- Some packages may not be found!
    Download error on https://pypi.python.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
    No local packages or download links found for cffi!=1.11.3,>=1.8
    Traceback (most recent call last):
    File "setup.py", line 275, in <module>
    **keywords_with_side_effects(sys.argv)
    File "/usr/lib64/python2.7/distutils/core.py", line 112, in setup
    _setup_distribution = dist = klass(attrs)
    File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 268, in init
    File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 313, in fetch_build_eggs
    File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 843, in resolve
    File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 1088, in best_match
    File "build/bdist.linux-x86_64/egg/pkg_resources/init.py", line 1100, in obtain
    File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 380, in fetch_build_egg
    File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 632, in easy_install

distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse(‘cffi!=1.11.3,>=1.8‘)
技术图片
安装cffi
l python setup.py build
l python setup.py install
技术图片
还是缺包
技术图片

又报错(估计还是缺包)
技术图片
该图片中报错关于Python.h的,并未找到相应的文件或目录,直接安装python3.4-devel,即可解决
yum install python-devel #因为我这ansible是用2版本的,所以后面装python-devel,python不带数字默认装2版本。

  1. 上传cryptography
    技术图片
    解压安装
    技术图片
    #python setup.py build
    #python setup.py install

  2. 解决问题,成功得到版本信息
    技术图片

看到这里能够成功获取到ansible的版本信息则说明ansible已经安装成功了。

以上是关于解决Ansible安装依赖问题的主要内容,如果未能解决你的问题,请参考以下文章

ansible介绍和安装

ansible自动化工具安装和简单使用

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

ansible自动化运维

ansible安装及使用

ansible 安装部署