Skip to content

package_facts module fails with 'not JSON serializable' error #85937

@mwilck

Description

@mwilck

Summary

The package_facts module fails the error message "Key of type 'bytes' is not JSON serializable by the 'module_legacy_m2c' profile". This happens for hosts with python3.11 and python311-rpm-4.14.3, e.g SUSE Linux Enterprise. I haven't seen it with other hosts.

Issue Type

Bug Report

Component Name

lib/ansible/modules/package_facts.py

Ansible Version

$ ansible --version
ansible [core 2.19.2]
  config file = /mnt/git/vagrant-test/ansible.cfg
  configured module search path = ['/home/mwilck/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.13/site-packages/ansible
  ansible collection location = /home/mwilck/.ansible/collections:/mnt/git/suse-labs-setup/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.13.7 (main, Aug 15 2025, 12:33:35) [GCC] (/usr/bin/python3.13)
  jinja version = 3.1.6
  pyyaml version = 6.0.2 (with libyaml v0.2.5)

Configuration

$ ansible-config dump --only-changed -t all
ANSIBLE_FORCE_COLOR(/mnt/git/vagrant-test/ansible.cfg) = False
CACHE_PLUGIN(/mnt/git/vagrant-test/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/mnt/git/vagrant-test/ansible.cfg) = facts
COLLECTIONS_PATHS(env: ANSIBLE_COLLECTIONS_PATH) = ['/home/mwilck/.ansible/collections', '/mnt/git/suse-labs-setup/collections', '/usr/share/ansible/collections']
CONFIG_FILE() = /mnt/git/vagrant-test/ansible.cfg
DEFAULT_FILTER_PLUGIN_PATH(/mnt/git/vagrant-test/ansible.cfg) = ['/mnt/git/vagrant-test/filter_plugins']
DEFAULT_GATHERING(/mnt/git/vagrant-test/ansible.cfg) = smart
DEFAULT_HOST_LIST(/mnt/git/vagrant-test/ansible.cfg) = ['/mnt/git/vagrant-test/inventory']
DEFAULT_KEEP_REMOTE_FILES(env: ANSIBLE_KEEP_REMOTE_FILES) = True
DEFAULT_ROLES_PATH(/mnt/git/vagrant-test/ansible.cfg) = ['/mnt/git/vagrant-test/roles']
DEFAULT_STDOUT_CALLBACK(/mnt/git/vagrant-test/ansible.cfg) = debug
DEFAULT_TIMEOUT(/mnt/git/vagrant-test/ansible.cfg) = 10
DEFAULT_TRANSPORT(/mnt/git/vagrant-test/ansible.cfg) = ssh
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /mnt/git/vagrant-test/helpers/vault-client
DISPLAY_SKIPPED_HOSTS(/mnt/git/vagrant-test/ansible.cfg) = False
EDITOR(env: EDITOR) = emacsclient
HOST_KEY_CHECKING(/mnt/git/vagrant-test/ansible.cfg) = False
INTERPRETER_PYTHON(/mnt/git/vagrant-test/ansible.cfg) = auto_silent
INVENTORY_ENABLED(/mnt/git/vagrant-test/ansible.cfg) = ['ini', 'yaml', 'community.libvirt.libvirt']
INVENTORY_IGNORE_EXTS(/mnt/git/vagrant-test/ansible.cfg) = ["('.pyc'", '.pyo', '.swp', '.bak', '~', '.rpm', '.md', '.txt', '.rst', '.orig', '.cfg', "'.retry')"]
PAGER(env: PAGER) = less

GALAXY_SERVERS:


CACHE:
=====

jsonfile:
________
_uri(/mnt/git/vagrant-test/ansible.cfg) = /mnt/git/vagrant-test/facts

CALLBACK:
========

default:
_______
display_skipped_hosts(/mnt/git/vagrant-test/ansible.cfg) = False
pretty_results(/mnt/git/vagrant-test/ansible.cfg) = True
result_format(/mnt/git/vagrant-test/ansible.cfg) = yaml

minimal:
_______
pretty_results(/mnt/git/vagrant-test/ansible.cfg) = True
result_format(/mnt/git/vagrant-test/ansible.cfg) = yaml

CONNECTION:
==========

paramiko_ssh:
____________
host_key_checking(/mnt/git/vagrant-test/ansible.cfg) = False
timeout(/mnt/git/vagrant-test/ansible.cfg) = 10

ssh:
___
host_key_checking(/mnt/git/vagrant-test/ansible.cfg) = False
ssh_args(/mnt/git/vagrant-test/ansible.cfg) = -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -4
timeout(/mnt/git/vagrant-test/ansible.cfg) = 10

OS / Environment

Admin workstation OS: OpenSUSE Tumbleweed 20250922

Host OS: OpenSUSE Leap 15.6
ansible_python_interpreter: /usr/bin/python3.11

python311-3.11.9-150600.3.3.1.x86_64
python311-rpm-4.14.3-150400.59.16.1.x86_64

Steps to Reproduce

$ ansible zeus -m package_facts 

Expected Results

package_facts succeeds

Actual Results

[ERROR]: Task failed: Module failed: Key of type 'bytes' is not JSON serializable by the 'module_legacy_m2c' profile.
Origin: <adhoc 'package_facts' task>

{'action': 'package_facts', 'args': {}, 'timeout': 0, 'async_val': 0, 'poll': 15}

zeus | FAILED! => 
    changed: false
    msg: 'Task failed: Module failed: Key of type ''bytes'' is not JSON serializable by
        the ''module_legacy_m2c'' profile.'

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects_2.19bugThis issue/PR relates to a bug.has_prThis issue has an associated PR.moduleThis issue/PR relates to a module.needs_triageNeeds a first human triage before being processed.verifiedThis issue has been verified/reproduced by maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions