diff --git a/changelogs/fragments/11001-omapi.yml b/changelogs/fragments/11001-omapi.yml new file mode 100644 index 0000000000..5131f763c0 --- /dev/null +++ b/changelogs/fragments/11001-omapi.yml @@ -0,0 +1,2 @@ +bugfixes: + - "omapi_host - make return values compatible with ansible-core 2.19 and Python 3 (https://github.com/ansible-collections/community.general/pull/11001)." diff --git a/plugins/modules/omapi_host.py b/plugins/modules/omapi_host.py index 36c5434fd5..c424f4c004 100644 --- a/plugins/modules/omapi_host.py +++ b/plugins/modules/omapi_host.py @@ -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