ansible报错Failed to import the required Python library
192.168.120.7 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on node1's Python /usr/bin/python. Please read module docume
ntation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No module named 'requests'"
python -c "import sys; print(sys.path)"
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']
对比
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/pip-19.2.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/fasteners-0.15-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/monotonic-1.5-py2.7.egg', '/usr/lib/python2.7/dist-packages']
似乎没有安装docker模块。 您需要通过系统包管理器(例如,apt安装python-docker)或使用pip安装它。 如果您有多个Python版本,请确保您已经将docker模块安装到Ansible正在使用的版本中。
安装python3 删除默认Python命令,软连python3,再单独执行
whereis python
cd /usr/bin
rm -rf python
ln -s python3.6 python
同样安装pip3
whereis python
cd /usr/bin
rm -rf pip
ln -s pip3.6 ip
再pip install docker-py,重新安装docker-py
ansible all -m docker_image -a 'name=calico/kube-controllers tag=v3.15.1 source=pull timeout=3600'