ansible.builtin.gather_facts fails with "Module result deserialization failed: No start of json char found"

Please replace this text with a description of your issue. You should:

Since upgrade from Debian 12 to Debian 13 we receive the following when running a playbook against a Windows system:

[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: DEFAULT_MANAGED_STR option. Reason: The `ansible_managed` variable can be set just like any other variable, or a different variable can be used.
Alternatives: Set the `ansible_managed` variable, or use any custom variable in templates. This feature will be removed from ansible-core version 2.23.

[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
[DEPRECATION WARNING]: The tree callback plugin is deprecated. This feature will be removed from ansible-core version 2.23.

PLAY [Configure Computer] **********************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************************************************************************
[WARNING]: Unhandled error in Python interpreter discovery for host 'timowin11': unexpected output from Python interpreter discovery

Unhandled error in Python interpreter discovery for host 'timowin11'.

<<< caused by >>>

unexpected output from Python interpreter discovery

[WARNING]: Host 'timowin11' is using the discovered Python interpreter at '/usr/bin/python3', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.19/reference_appendices/interpreter_discovery.html for more information.
[ERROR]: Task failed: Action failed: The following modules failed to execute: ansible.legacy.setup.

Task failed: Action failed.

<<< caused by >>>

The following modules failed to execute: ansible.legacy.setup.

+--[ Sub-Event 1 of 1 ]---
|
| Module result deserialization failed: No start of json char found See stdout/stderr for the returned output.
|
+--[ End Sub-Event ]---

fatal: [timowin11]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "exception": "(traceback unavailable)", "failed": true, "module_stderr": "/bin/sh : The term '/bin/sh' is not recognized as the name of a cmdlet, function, script file, or \r\noperable program. Check the spelling of the name, or if a path was included, verify that the path \r\nis correct and try again.\r\nAt line:1 char:1\r\n+ /bin/sh -c '/usr/bin/python3 && sleep 0'\r\n+ ~~~~~~~\r\n    + CategoryInfo          : ObjectNotFound: (/bin/sh:String) [], CommandNotFoundException\r\n    + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\n", "module_stdout": "", "msg": "Module result deserialization failed: No start of json char found", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup."}

PLAY RECAP *************************************************************************************************************************************************************************************************************************************
timowin11                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
ansible --version
ansible [core 2.19.4]
  config file = /opt/code/ceos/admin/ansible.cfg
  configured module search path = ['/home/timoses/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /opt/code/ceos/admin/collections:/home/timoses/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.13.5 (main, Jun 25 2025, 18:55:22) [GCC 14.2.0] (/usr/bin/python3)
  jinja version = 3.1.6
  pyyaml version = 6.0.2 (with libyaml v0.2.5)

Any ideas what the cause may be?

Did your ansible version change when you did your upgrade, or just the OS version its running on?

Hey, @Timoses . Welcome to the forum.

Is timowin11 a Windows host? If so, should it be looking for /bin/sh?
How is your connection to timowin11 configured?

It is a windows11 machine.

Usually the gather_facts module should forward to the windows setup module. However, it does not seem to do this.

Of course /bin/sh is doomed to fail on Windows..

What is odd is that towards another windows11 machine it works without problems:

TASK [my_col.base.all : ansible.builtin.gather_facts] ********************************************************************************************************************************************************************************************
task path: /opt/code/ansible/collections/ansible_collections/my_col/base/roles/all/tasks/main.yml:28
redirecting (type: modules) ansible.builtin.setup to ansible.windows.setup
ok: [lama1.nodomain]

I’m not sure how the logic of detecting which gather_facts module Ansible uses works, but it seems to fail in this instance and I’m not sure why.

Yes, Ansible version changed:

Bookworm: 2.14 Debian -- Details of package ansible-core in bookworm
Trixie: 2.19 Debian -- Details of package ansible-core in trixie

Review Windows SSH — Ansible Community Documentation and ensure your controller is configured to handle timowin11 as a Windows machine.

2 Likes

Yeah, sorry. I accidentally forgot to add the host to the [windows] group which defines these variables.

Thanks for the hint!!

2 Likes