由于每台机器的环境都不尽相同,存在某些机器的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
mycli = getattr(import("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
File "/usr/lib/python2.7/site-packages/ansible/cli/init.py", line 38, in
from ansible.inventory.manager import InventoryManager
File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py", line 33, in
from ansible.plugins.loader import inventory_loader
File "/usr/lib/python2.7/site-packages/ansible/plugins/loader.py", line 22, in
from ansible.parsing.utils.yaml import from_yaml
File "/usr/lib/python2.7/site-packages/ansible/parsing/utils/yaml.py", line 17, in
from ansible.parsing.yaml.loader import AnsibleLoader
File "/usr/lib/python2.7/site-packages/ansible/parsing/yaml/loader.py", line 30, in
from ansible.parsing.yaml.constructor import AnsibleConstructor
File "/usr/lib/python2.7/site-packages/ansible/parsing/yaml/constructor.py", line 29, in
from ansible.parsing.vault import VaultLib
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/init.py", line 45, in
from cryptography.hazmat.backends import default_backend
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/init.py", line 7, in
import pkg_resources
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 3011, in
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
    解决Ansible安装依赖问题
    这里Setuptools版本需要大于等于18.5.
    解决Ansible安装依赖问题

  2. 解压安装
    解决Ansible安装依赖问题
    #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
    **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')
解决Ansible安装依赖问题
安装cffi
l python setup.py build
l python setup.py install
解决Ansible安装依赖问题_第1张图片
还是缺包
解决Ansible安装依赖问题_第2张图片

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

  1. 上传cryptography
    解决Ansible安装依赖问题
    解压安装
    解决Ansible安装依赖问题
    #python setup.py build
    #python setup.py install

  2. 解决问题,成功得到版本信息
    解决Ansible安装依赖问题

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