"msg": "winrm or requests is not installed: No module named winrm"

Hi All,

i am facing some issue while trying to connect to windows.
please help.

ansible windows -i hosts -m win_ping

xxxxx | FAILED! => {
“msg”: “winrm or requests is not installed: No module named winrm”
}

i can see winrm is installed.

output of pip list:

Package Version


ansible-tower-cli 3.3.4
asn1crypto 0.24.0
backports.ssl-match-hostname 3.7.0.1
bcrypt 3.1.6
cached-property 1.5.1
certifi 2019.9.11
cffi 1.12.3
chardet 3.0.4
Click 7.0
colorama 0.4.1
cryptography 2.7
docker 3.7.3
docker-compose 1.24.1
docker-pycreds 0.4.0
dockerpty 0.4.1
docopt 0.6.2
enum34 1.1.6
functools32 3.2.3.post2
idna 2.7
ipaddress 1.0.22
jsonschema 2.6.0
ntlm-auth 1.4.0
paramiko 2.4.2
pip 19.2.3
pyasn1 0.4.5
pycparser 2.19
PyNaCl 1.3.0
pyOpenSSL 19.0.0
pywinrm 0.3.0
PyYAML 3.13
requests 2.20.1
requests-ntlm 1.1.0
setuptools 0.9.8
six 1.12.0
texttable 0.9.1
urllib3 1.24.3
websocket-client 0.56.0
xmltodict 0.12.0

Python 2.7.13 (default, May 23 2018, 14:21:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import winrm
import requests

exit()

ansible --version
ansible 2.7.12
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible
python version = 2.7.13 (default, May 23 2018, 14:21:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

It could be that the Python Ansible is using is not the same as the python in the main path. You can check all this by running;

`

Check what Python comes first in the PATH and what Python pip is using

which python
pip --version

Check what Python Ansible is configured to run as

head -n 1 $(which ansible)

`

If the shebang in ansible is ‘#!/usr/bin/env python’ then it should be using the Python in the main path but if it’s another value and not what ‘which python’ returns then you need to make sure that either;

  • You install pywinrm to that Python environment, or
  • You install ansible to the Python environment that has pywinrm and other packages installed to

Thanks

Jordan