问题描述:
ansible 调用远程widows服务器,执行报错
报错信息:
winrm or requests is not installed: No module named winrm
环境:
ansible版本:ansible 2.9.27 #yum安装
python版本:python version = 2.7.5 #系统默认
同时系统上安装了python3.6.8 #yum安装
系统没有安装pip2,ansible默认使用的python2
并且由于python2已经弃用,即使安装pip2后,任然无法安装pywinrm,报错如下
python -m pip install pywinrm-0.4.3-py2.py3-none-any.whl
Processing ./pywinrm-0.4.3-py2.py3-none-any.whl
Collecting xmltodict (from pywinrm==0.4.3)
Using cached https://files.pythonhosted.org/packages/94/db/fd0326e331726f07ff7f40675cd86aa804bfd2e5016c727fa761c934990e/xmltodict-0.13.0-py2.py3-none-any.whl
Collecting requests>=2.9.1 (from pywinrm==0.4.3)
Using cached https://files.pythonhosted.org/packages/a5/61/a867851fd5ab77277495a8709ddda0861b28163c4613b011bc00228cc724/requests-2.28.1.tar.gz
Complete output from command python setup.py egg_info:
==========================
Unsupported Python version
==========================
This version of Requests requires at least Python 3.7, but
you're trying to install it on Python 2.7. To resolve this,
consider upgrading to a supported Python version.
If you can't upgrade your Python version, you'll need to
pin to an older version of Requests (<2.28).
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-zToSeV/requests/
You are using pip version 8.1.2, however version 22.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
因此用pip3安装了pywinrm,并且执行ansible时指定了python3作为解释环境,但是在这里并没有起作用
ansible -i hosts rwin -m win_ping -e 'ansible_python_interpreter=/usr/bin/python3'
解决办法:
升级ansible版本:
python3 -m pip install ansible
source /etc/profile
ansible --vesion