1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

[PR #11001/eb6337c0 backport][stable-11] omapi_host: fix bytes vs. str confusion (#11022)

omapi_host: fix bytes vs. str confusion (#11001)

* omapi_host: fix bytes vs. str confusion

After an update of the control node from Debian
bookworm to trixie, the omapi_host module fails to
work with the error message:

Key of type 'bytes' is not JSON serializable by the
'module_legacy_m2c' profile.

https://github.com/ansible/ansible/issues/85937 had the
same error, but the fix is a bit more intricate here
because the result dict is dynamically generated from
an API response object.

This also fixes unpacking the MAC and IP address and
hardware type, which were broken for Python3.

* Merge suggestion for changelog fragment



* do not unpack_ip twice

Noticed by Felix Fontein <felix@fontein.de>

* mention py3k in changelog fragment, too

---------


(cherry picked from commit eb6337c0c9)

Co-authored-by: mirabilos <tg@mirbsd.org>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-10-30 20:30:00 +01:00 committed by GitHub
parent 23cc57c9f6
commit cd50836977
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View file

@ -146,7 +146,7 @@ except ImportError:
pureomapi_found = False
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.common.text.converters import to_bytes, to_native
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
class OmapiHostManager:
@ -178,15 +178,18 @@ class OmapiHostManager:
@staticmethod
def unpack_facts(obj):
result = dict(obj)
result = {}
for k, v in dict(obj).items():
result[to_text(k)] = v
if 'hardware-address' in result:
result['hardware-address'] = to_native(unpack_mac(result[to_bytes('hardware-address')]))
result['hardware-address'] = to_native(unpack_mac(result['hardware-address']))
if 'ip-address' in result:
result['ip-address'] = to_native(unpack_ip(result[to_bytes('ip-address')]))
result['ip-address'] = to_native(unpack_ip(result['ip-address']))
if 'hardware-type' in result:
result['hardware-type'] = struct.unpack("!I", result[to_bytes('hardware-type')])
result['hardware-type'] = struct.unpack("!I", result['hardware-type'])
return result
@ -234,8 +237,8 @@ class OmapiHostManager:
response_obj = self.unpack_facts(host_response.obj)
fields_to_update = {}
if to_bytes('ip-address', errors='surrogate_or_strict') not in response_obj or \
unpack_ip(response_obj[to_bytes('ip-address', errors='surrogate_or_strict')]) != self.module.params['ip']:
if 'ip-address' not in response_obj or \
response_obj['ip-address'] != self.module.params['ip']:
fields_to_update['ip-address'] = pack_ip(self.module.params['ip'])
# Name cannot be changed