A few months ago, I was able to set up an ansible environment in a Virtual environment on a Ubuntu 24.04 server.
I use it mainly to manage Windows Servers through WinRM with a kerberos authentication.
I communicate on TCP/5985 port, and everything works fine.
Lately, I tried to reproduce the same configuration. I mean setting up an ansible environment in a venv to manage Windows Servers.
But it became impossible to properly communicate with Windows Servers using WinRM and kerberos. A simple win_ping shows the error.
On the working machine:
On the latest ansible environment installed:
If I execute the same thing in very verbose mode on both machines:
In text mode, the full error message:
Citation
user@semaphoreui:~$ source ~/venv/ansible2.17_python3.12/bin/activate;ansible -m win_ping -i ~/windows_hosts SERVER -k -vvvvvv;deactivate
ansible [core 2.18.0]
config file = None
configured module search path = [‘/home/user/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /home/user/venv/ansible2.17_python3.12/bin/ansible
python version = 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] (/home/user/venv/ansible2.17_python3.12/bin/python3.12)
jinja version = 3.1.4
libyaml = True
No config file found; using defaults
SSH password:
setting up inventory plugins
Loading collection ansible.builtin from
host_list declined parsing /home/user/windows_hosts as it did not pass its verify_file() method
script declined parsing /home/user/windows_hosts as it did not pass its verify_file() method
auto declined parsing /home/user/windows_hosts as it did not pass its verify_file() method
Parsed /home/user/windows_hosts inventory source with ini plugin
redirecting (type: modules) ansible.builtin.win_ping to ansible.windows.win_ping
Loading collection ansible.windows from /home/user/.ansible/collections/ansible_collections/ansible/windows
Loading callback plugin minimal of type stdout, v2.0 from /home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/ansible/plugins/callback/minimal.py
Attempting to use ‘default’ callback.
Skipping callback ‘default’, as we already have a stdout callback.
Attempting to use ‘junit’ callback.
Attempting to use ‘minimal’ callback.
Skipping callback ‘minimal’, as we already have a stdout callback.
Attempting to use ‘oneline’ callback.
Skipping callback ‘oneline’, as we already have a stdout callback.
Attempting to use ‘tree’ callback.
redirecting (type: modules) ansible.builtin.win_ping to ansible.windows.win_ping
redirecting (type: modules) ansible.builtin.win_ping to ansible.windows.win_ping
Using module file /home/user/.ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_ping.ps1
Pipelining is enabled.
<SERVER.ENTERPRISE.COM> ESTABLISH WINRM CONNECTION FOR USER: THE-WINUSER@ENTERPRISE.COM on PORT 5985 TO SERVER.ENTERPRISE.COM
creating Kerberos CC at /tmp/tmpfeohiy61
calling kinit with subprocess for principal THE-WINUSER@ENTERPRISE.COM
kinit succeeded for principal THE-WINUSER@ENTERPRISE.COM
<SERVER.ENTERPRISE.COM> WINRM CONNECT: transport=kerberos endpoint=http://SERVER.ENTERPRISE.COM:5985/wsman
<SERVER.ENTERPRISE.COM> WINRM CONNECTION ERROR: Bad HTTP response returned from server. Code 500
Traceback (most recent call last):
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 268, in send_message
root = ET.fromstring(ex.response_text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/xml/etree/ElementTree.py”, line 1336, in XML
return parser.close()
^^^^^^^^^^^^^^
xml.etree.ElementTree.ParseError: no element found: line 1, column 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/ansible/plugins/connection/winrm.py”, line 483, in _winrm_connect
self.shell_id = protocol.open_shell(codepage=65001) # UTF-8
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 193, in open_shell
res = self.send_message(xmltodict.unparse(req))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 271, in send_message
raise ex
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 263, in send_message
resp = self.transport.send_message(message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/transport.py”, line 336, in send_message
response = self._send_message_request(session, prepared_request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/transport.py”, line 352, in _send_message_request
raise WinRMTransportError(“http”, ex.response.status_code, response_text.decode())
winrm.exceptions.WinRMTransportError: Bad HTTP response returned from server. Code 500
SERVER | UNREACHABLE! => {
“changed”: false,
“msg”: “kerberos: Bad HTTP response returned from server. Code 500”,
“unreachable”: true
}
Here is the environment details on the running machine:
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble
pip freeze
ansible-core==2.17.3
certifi==2024.8.30
cffi==1.17.0
charset-normalizer==3.3.2
cryptography==43.0.0
decorator==5.1.1
gssapi==1.8.3
idna==3.8
Jinja2==3.1.4
jmespath==1.0.1
kerberos==1.3.1
krb5==0.6.0
MarkupSafe==2.1.5
packaging==24.1
pycparser==2.22
pykerberos==1.2.4
pyspnego==0.11.1
pywinrm==0.5.0
PyYAML==6.0.2
requests==2.32.3
requests-kerberos==0.15.0
requests_ntlm==1.3.0
resolvelib==1.0.1
urllib3==2.2.2
xmltodict==0.13.0
Collection Version
ansible.posix 1.5.4
ansible.utils 5.1.1
ansible.windows 2.4.0
chocolatey.chocolatey 1.5.1
community.crypto 2.21.1
community.dns 3.0.2
community.general 9.1.0
community.library_inventory_filtering_v1 1.0.1
community.mysql 3.10.3
community.vmware 4.5.0
community.windows 2.2.0
microsoft.ad 1.6.0
vmware.vmware 1.3.0
On the non-working machines, I’ve tried to install exactly the same pip packages’ version or the latest version. Whatever I try, I always get this:
kerberos: Bad HTTP response returned from server. Code 500
error message.
As we can see, the WinRM connection is clearly established:
ESTABLISH WINRM CONNECTION FOR USER: USER@ENTERPRISE.COM on PORT 5985 TO SERVER.ENTERPRISE.COM
creating Kerberos CC at /tmp/tmpfeohiy61
and the kerberos authentication is OK:
calling kinit with subprocess for principal USER@ENTERPRISE.COM
kinit succeeded for principal USER@ENTERPRISE.COM
<SERVER.ENTERPRISE.COM> WINRM CONNECT: transport=kerberos endpoint=http://SERVER.ENTERPRISE.COM:5985/wsman
And then:
<SERVER.ENTERPRISE.COM> WINRM CONNECTION ERROR: Bad HTTP response returned from server. Code 500
Traceback (most recent call last):
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 268, in send_message
root = ET.fromstring(ex.response_text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/xml/etree/ElementTree.py”, line 1336, in XML
return parser.close()
^^^^^^^^^^^^^^
xml.etree.ElementTree.ParseError: no element found: line 1, column 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/ansible/plugins/connection/winrm.py”, line 483, in _winrm_connect
self.shell_id = protocol.open_shell(codepage=65001) # UTF-8
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 193, in open_shell
res = self.send_message(xmltodict.unparse(req))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 271, in send_message
raise ex
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/protocol.py”, line 263, in send_message
resp = self.transport.send_message(message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/transport.py”, line 336, in send_message
response = self._send_message_request(session, prepared_request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/user/venv/ansible2.17_python3.12/lib/python3.12/site-packages/winrm/transport.py”, line 352, in _send_message_request
raise WinRMTransportError(“http”, ex.response.status_code, response_text.decode())
winrm.exceptions.WinRMTransportError: Bad HTTP response returned from server. Code 500
SERVER | UNREACHABLE! => {
“changed”: false,
“msg”: “kerberos: Bad HTTP response returned from server. Code 500”,
“unreachable”: true
}
I’ve tried many things, and I do know how to fix this very annoying issue.
I really need you help.