Rainbond工程师教你如何快速解决安装ansible失败的问题

在大多数情况下,ansible安装失败的原因是因为网络不稳定,此时在安装失败的节点尝试手动安装ansible即可

pip install ansible==2.8.5 -i https://pypi.tuna.tsinghua.edu.cn/simple

如果安装成功,则继续执行节点安装命令即可,如果安装失败,你可以接着往下看

以下案例为在阿里云做过snat,在其网络代理的节点中安装时出现的报错

TASK [node/exm : Rainbond | Install ansible Online] *********************************************************************************************************************************************************
fatal: [5e44f517-d197-46b9-bbbe-7e6ea3260e45]: FAILED! => {"changed": true, "cmd": "pip install ansible==2.8.5", "delta": "0:00:18.151627", "end": "2019-12-26 20:24:45.329137", "msg": "non-zero return code24:27.177510", "stderr": "Command \"python setup.py egg_info\" failed with error code 1 in /tmp/pip-build-ZPkaft/ansible/\nYou are using pip version 8.1.2, however version 19.3.1 is available.\nYou should all --upgrade pip' command.", "stderr_lines": ["Command \"python setup.py egg_info\" failed with error code 1 in /tmp/pip-build-ZPkaft/ansible/", "You are using pip version 8.1.2, however version 19.3.1 ispgrading via the 'pip install --upgrade pip' command."], "stdout": "Collecting ansible==2.8.5\n  Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/04/25/48fee5f8048360d9375e01846fcf395dda58242ed1.gz (14.4MB)\n    Complete output from command python setup.py egg_info:\n    Traceback (most recent call last):\n      File \"<string>\", line 1, in <module>\n      File \"/tmp/pip-build-ZPkaft/ansible/se     main()\n      File \"/tmp/pip-build-ZPkaft/ansible/setup.py\", line 325, in main\n        setup(**setup_params)\n      File \"/usr/lib64/python2.7/distutils/core.py\", line 112, in setup\n        _set)\n      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 269, in __init__\n        _Distribution.__init__(self,attrs)\n      File \"/usr/lib64/python2.7/distutils/dist.py\", line 287, inions()\n      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 302, in finalize_options\n        ep.load()(self, ep.name, value)\n      File \"/usr/lib/python2.7/site-packages/pkg_resourc\n        return self.resolve()\n      File \"/usr/lib/python2.7/site-packages/pkg_resources/__init__.py\", line 2351, in resolve\n        raise ImportError(str(exc))\n    ImportError: 'module' object has \n    ----------------------------------------", "stdout_lines": ["Collecting ansible==2.8.5", "  Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/04/25/48fee5f8048360d9375e01846fcf395dda58242edr.gz (14.4MB)", "    Complete output from command python setup.py egg_info:", "    Traceback (most recent call last):", "      File \"<string>\", line 1, in <module>", "      File \"/tmp/pip-build-ZPkaft/aule>", "        main()", "      File \"/tmp/pip-build-ZPkaft/ansible/setup.py\", line 325, in main", "        setup(**setup_params)", "      File \"/usr/lib64/python2.7/distutils/core.py\", line 112, in se dist = klass(attrs)", "      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 269, in __init__", "        _Distribution.__init__(self,attrs)", "      File \"/usr/lib64/python2.7/distutil "        self.finalize_options()", "      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 302, in finalize_options", "        ep.load()(self, ep.name, value)", "      File \"/usr/lib/py__init__.py\", line 2341, in load", "        return self.resolve()", "      File \"/usr/lib/python2.7/site-packages/pkg_resources/__init__.py\", line 2351, in resolve", "        raise ImportError(str(exc)) has no attribute 'check_specifier'", "    ", "    ----------------------------------------"]}
Thursday 26 December 2019  20:24:45 +0800 (0:00:18.288)       0:02:38.516 ***** 

PLAY RECAP **************************************************************************************************************************************************************************************************
5e44f517-d197-46b9-bbbe-7e6ea3260e45 : ok=114  changed=81   unreachable=0    failed=1    skipped=81   rescued=0    ignored=0   


ERROR MESSAGE SUMMARY ***************************************************************************************************************************************************************************************
[5e44f517-d197-46b9-bbbe-7e6ea3260e45]: Ansible FAILED! => playbook: addmaster.yml; TASK: node/exm : Rainbond | Install ansible Online; message: {"changed": true, "cmd": "pip install ansible==2.8.5", "delt2-26 20:24:45.329137", "msg": "non-zero return code", "rc": 1, "start": "2019-12-26 20:24:27.177510", "stderr": "Command \"python setup.py egg_info\" failed with error code 1 in /tmp/pip-build-ZPkaft/ansib, however version 19.3.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.", "stderr_lines": ["Command \"python setup.py egg_info\" failed with error code 1 in /tmp/ using pip version 8.1.2, however version 19.3.1 is available.", "You should consider upgrading via the 'pip install --upgrade pip' command."], "stdout": "Collecting ansible==2.8.5\n  Downloading http://mies/04/25/48fee5f8048360d9375e01846fcf395dda58242ed1f25a2106b6794452eb/ansible-2.8.5.tar.gz (14.4MB)\n    Complete output from command python setup.py egg_info:\n    Traceback (most recent call last):\n    ule>\n      File \"/tmp/pip-build-ZPkaft/ansible/setup.py\", line 330, in <module>\n        main()\n      File \"/tmp/pip-build-ZPkaft/ansible/setup.py\", line 325, in main\n        setup(**setup_params)\nstutils/core.py\", line 112, in setup\n        _setup_distribution = dist = klass(attrs)\n      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 269, in __init__\n        _Distribution.__r/lib64/python2.7/distutils/dist.py\", line 287, in __init__\n        self.finalize_options()\n      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 302, in finalize_options\n        ep.File \"/usr/lib/python2.7/site-packages/pkg_resources/__init__.py\", line 2341, in load\n        return self.resolve()\n      File \"/usr/lib/python2.7/site-packages/pkg_resources/__init__.py\", line 2351,or(str(exc))\n    ImportError: 'module' object has no attribute 'check_specifier'\n    \n    ----------------------------------------", "stdout_lines": ["Collecting ansible==2.8.5", "  Downloading http://mges/04/25/48fee5f8048360d9375e01846fcf395dda58242ed1f25a2106b6794452eb/ansible-2.8.5.tar.gz (14.4MB)", "    Complete output from command python setup.py egg_info:", "    Traceback (most recent call last):"in <module>", "      File \"/tmp/pip-build-ZPkaft/ansible/setup.py\", line 330, in <module>", "        main()", "      File \"/tmp/pip-build-ZPkaft/ansible/setup.py\", line 325, in main", "        setup(**ib64/python2.7/distutils/core.py\", line 112, in setup", "        _setup_distribution = dist = klass(attrs)", "      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 269, in __init__", " ttrs)", "      File \"/usr/lib64/python2.7/distutils/dist.py\", line 287, in __init__", "        self.finalize_options()", "      File \"/usr/lib/python2.7/site-packages/setuptools/dist.py\", line 302, in )(self, ep.name, value)", "      File \"/usr/lib/python2.7/site-packages/pkg_resources/__init__.py\", line 2341, in load", "        return self.resolve()", "      File \"/usr/lib/python2.7/site-packages/pk, in resolve", "        raise ImportError(str(exc))", "    ImportError: 'module' object has no attribute 'check_specifier'", "    ", "    ----------------------------------------"]}

解决办法如下

#卸载setuptools
pip uninstall setuptools

#升级pip版本
pip install --upgrade pip

#安装指定版本的setuptools

pip install setuptools==30.1.0

#重新安装ansible

pip install ansible==2.8.5 -i http://mirrors.cloud.aliyuncs.com/pypi/simple/

如果安装成功,则继续执行节点安装命令,如果安装失败,请跟帖描述你的问题,Rainbond工程师将尽快为你解答。