CentOS7配置Ansible管理Windows主机时遇winrm相关报错
Hey there, let's work through this Ansible win_ping error you're facing. That No module named xmltodict message is pointing straight to the missing piece here—even though you installed winrm and requests, xmltodict is another critical dependency that Ansible needs to parse XML responses from Windows hosts.
Here's how to get this sorted:
1. Install xmltodict via pip
First, make sure pip is set up on your CentOS7 system (skip if you already have it):
sudo yum install python-pip -y
Then install the missing xmltodict module:
sudo pip install xmltodict
If you're using Python 3 (recommended for newer Ansible versions), swap out pip for pip3:
sudo yum install python3-pip -y sudo pip3 install xmltodict
2. Verify the installation
Double-check that the module is properly installed with this quick test:
# For Python 2 python -c "import xmltodict; print('xmltodict is installed successfully')" # For Python 3 python3 -c "import xmltodict; print('xmltodict is installed successfully')"
If you see the confirmation message, you're ready to move on.
3. Retest your win_ping command
Run your original command again:
ansible host_group -i hosts -m win_ping
This should now work, assuming your Windows host's WinRM configuration is set up correctly (which it sounds like you've covered from the guides you followed).
Bonus: Install all Windows-related dependencies at once
To avoid hitting similar missing module issues later, install the full set of required packages in one go:
# For Python 2 sudo pip install pywinrm requests xmltodict # For Python 3 sudo pip3 install pywinrm requests xmltodict
That should cover all the base dependencies Ansible needs to communicate smoothly with your Windows hosts.
内容的提问来源于stack exchange,提问作者Shaun Aran

