Why Am I Getting "winrm or requests is not installed: No module named xmltodict" Error with Ansible Engine Managing Windows Hosts?

Solution Unverified - Updated -

Environment

  • Ansible Engine

Issue

Unable to interface with Windows hosts on a new Ansible control host

Resolution

Install package :

# pip install "pywinrm>=0.2.2"

Please Note: You need to run the Windows provisioning powershell script on the windows host to configure winrm for Ansible. Please refer to our documentation: Windows System Preparation.

Root Cause

Ansible requires the winrm Python module to interface with Windows remote hosts. For more details, see Windows Support: Installing on the Control Machine

Diagnostic Steps

  • Run the below command :
# ansible windows -i hosts -m win_ping
x.x.x.x | FAILED! => {
    "msg": "winrm or requests is not installed: No module named xmltodict"
}

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

2 Comments

This solution also handles the python module called winrm (instead of xmldict)

winrm or requests is not installed: No module named winrm

thinkred1cartoon:$ ansible all -i hosts.txt -m win_ping
172.16.96.135 | FAILED! => {
    "msg": "winrm or requests is not installed: cannot import name certs"


I was getting this error even if python2-winrm version 0.3.0 is already installed via yum

yum list installed | grep winrm
python2-winrm.noarch              0.3.0-1.el7                @epel

pip install "pywinrm>=0.2.2" only resulted in "Requirement already satisfied"

I ran this to resolve the error - 

1)     yum autoremove python2-winrm.noarch

2)    pip install "pywinrm>=0.2.2"

Then ping: pong worked just fine over https, port=5986

ram@thinkred1cartoon$ ansible all -i hosts.txt -m win_ping
172.16.96.135 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

conversely, if you don't want to run command 1, then command 2 won't work for you. 
In that case, run command 3

3 ) pip install --ignore-installed "pywinrm>=0.2.2"


ram@thinkred1cartoon$ cat hosts.txt           #A quick peek into the inventory file 

[win]
172.16.96.135

[win:vars]
ansible_user='Raman'
ansible_password='XXXXX'
#ansible_port=5985
ansible_port=5986
ansible_connection=winrm
#ansible_winrm_scheme=http
ansible_winrm_scheme=https
ansible_winrm_server_cert_validation=ignore