I’m new to Ansible but have set it up on Red Hat 9 and can ping and ssh from my Red Hat server to the Windows 2022 server fine but I can’t ping/connect to the Windows server with Ansible. Could someone help with this issue?
- my code!
Set at least one tag (the experts follow the tags, so the right people will find you if you tag)
To be able to help, we’ll need some details about your environment, connection settings, and an error message at least.
Inventory below named test
[win]
192.168.20.132
[win:vars]
ansible_user=root
ansible_password=mypassword
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_winrm_server_cert_validation=ignore
ansible_port=5986
Error I receive when trying to run the following command.
ansible -all -m ping -i test
[WARNING]: Unhandled error in Python interpreter discovery for host 192.168.20.132: winrm or requests is not installed:
No module named ‘winrm’
192.168.20.132 | FAILED! => {
“msg”: “winrm or requests is not installed: No module named ‘winrm’”
Any help to resolve this would be greatly appreciated.
First, for trying to ping
windows hosts, you might want to check out the win_ping module instead.
But, the error message here tells you exactly what you’re missing, too
to resolve this, you’ll need to do something like
pip install pywinrm
pip install requests
Lyle_McKarns:
pip install requests
HI Lyle, thanks for the help after running the commands in your response now I receive this error.
ansible all -m win_ping -i test
192.168.20.132 | FAILED! => {
“msg”: “The module win_ping was redirected to ansible.windows.win_ping, which could not be loaded.”
You can check if ansible.windows
is installed with
ansible-galaxy collection list | grep windows
and if its not, you can install it with
ansible-galaxy collection install ansible.windows
Had to install it.
ansible-galaxy collection list | grep windows
ansible.windows 3.0.0
Now error seems to be the somewhat the same
192.168.20.132 | FAILED! => {
“msg”: “winrm or requests is not installed: No module named ‘winrm’”
Per the second portion of my earlier post, you’ll need to install those bits.
I did previously
pip install pywinrm
Requirement already satisfied: pywinrm in /usr/local/lib/python3.9/site-packages (0.5.0)
Requirement already satisfied: xmltodict in /usr/local/lib/python3.9/site-packages (from pywinrm) (0.14.2)
Requirement already satisfied: requests>=2.9.1 in /usr/lib/python3.9/site-packages (from pywinrm) (2.25.1)
Requirement already satisfied: requests-ntlm>=1.1.0 in /usr/local/lib/python3.9/site-packages (from pywinrm) (1.3.0)
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3.9/site-packages (from requests>=2.9.1->pywinrm) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3.9/site-packages (from requests>=2.9.1->pywinrm) (1.26.5)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/lib/python3.9/site-packages (from requests>=2.9.1->pywinrm) (4.0.0)
Requirement already satisfied: cryptography>=1.3 in /usr/local/lib64/python3.9/site-packages (from requests-ntlm>=1.1.0->pywinrm) (44.0.3)
Requirement already satisfied: pyspnego>=0.4.0 in /usr/local/lib/python3.9/site-packages (from requests-ntlm>=1.1.0->pywinrm) (0.11.2)
Requirement already satisfied: cffi>=1.12 in /usr/local/lib64/python3.9/site-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->pywinrm) (1.17.1)
Requirement already satisfied: pycparser in /usr/local/lib/python3.9/site-packages (from cffi>=1.12->cryptography>=1.3->requests-ntlm>=1.1.0->pywinrm) (2.22)
pip install requests
Requirement already satisfied: requests in /usr/lib/python3.9/site-packages (2.25.1)
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3.9/site-packages (from requests) (2.10)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/lib/python3.9/site-packages (from requests) (4.0.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3.9/site-packages (from requests) (1.26.5)
Is that the same instance of python that ansible is using?
I’m not sure. How to check and correct?
ansible --version
ansible [core 2.16.14]
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/root/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.9 (main, Apr 2 2025, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-5)] (/usr/bin/python3.11)
jinja version = 3.1.5
libyaml = True
It looks like you installed the modules into a python3.9 environment
But ansible is running for a 3.11.9 environment (at a different path).
So, while they are installed, they’re not usable by ansible. You could do something like
/usr/bin/python3.11 -m pip install pywinrm requests
to ensure that the modules required are installed in the correct environment
Didn’t work…
/usr/bin/python3.11 -m pip install pywinrm requests
/usr/bin/python3.11: No module named pip
Maybe this is an effort in futility.
/usr/bin/python3.11 -m pip install pywinrm requests
Collecting pywinrm
Using cached pywinrm-0.5.0-py3-none-any.whl (48 kB)
Requirement already satisfied: requests in /usr/lib/python3.11/site-packages (2.28.1)
Collecting requests-ntlm>=1.1.0
Using cached requests_ntlm-1.3.0-py3-none-any.whl (6.6 kB)
Collecting xmltodict
Using cached xmltodict-0.14.2-py2.py3-none-any.whl (10.0 kB)
Requirement already satisfied: charset_normalizer<3,>=2 in /usr/lib/python3.11/site-packages (from requests) (2.1.0)
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3.11/site-packages (from requests) (3.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3.11/site-packages (from requests) (1.26.12)
Requirement already satisfied: cryptography>=1.3 in /usr/lib64/python3.11/site-packages (from requests-ntlm>=1.1.0->pywinrm) (42.0.5)
Collecting pyspnego>=0.4.0
Using cached pyspnego-0.11.2-py3-none-any.whl (130 kB)
Requirement already satisfied: cffi>=1.12 in /usr/lib64/python3.11/site-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->pywinrm) (1.15.1)
Requirement already satisfied: pycparser in /usr/lib/python3.11/site-packages (from cffi>=1.12->cryptography>=1.3->requests-ntlm>=1.1.0->pywinrm) (2.20)
Requirement already satisfied: ply==3.11 in /usr/lib/python3.11/site-packages (from pycparser->cffi>=1.12->cryptography>=1.3->requests-ntlm>=1.1.0->pywinrm) (3.11)
Installing collected packages: xmltodict, pyspnego, requests-ntlm, pywinrm
Successfully installed pyspnego-0.11.2 pywinrm-0.5.0 requests-ntlm-1.3.0 xmltodict-0.14.2
Then ran
ansible all -m win_ping -i test
192.168.20.132 | SUCCESS => {
“changed”: false,
“ping”: “pong”
Thanks for the help. Greatly appreciated
For windows hosts you still need to use win_ping
jskorzyn
(Jacek Skorzynski)
May 8, 2025, 2:01pm
19
Hi,
If you chose to try OpenSSH instead of winrm it might be much easier.
Seems like OpenSSH is already running on your Windows machine as you claim in initial post
All you need to set up is ansible _shell_type variable set to cmd or powershell (depends on your default shell ).
All is nicely documented here: Windows SSH — Ansible Community Documentation