diff --git a/changelogs/fragments/57919-python3-encoding-iosxr_config.yaml b/changelogs/fragments/57919-python3-encoding-iosxr_config.yaml new file mode 100644 index 00000000000..15759961195 --- /dev/null +++ b/changelogs/fragments/57919-python3-encoding-iosxr_config.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Fix python3 encoding issue with iosxr_config. diff --git a/lib/ansible/modules/network/iosxr/iosxr_config.py b/lib/ansible/modules/network/iosxr/iosxr_config.py index 63fac281fa7..bab06f039e7 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_config.py +++ b/lib/ansible/modules/network/iosxr/iosxr_config.py @@ -236,7 +236,7 @@ time: """ import re -from ansible.module_utils._text import to_text +from ansible.module_utils._text import to_text, to_bytes from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.connection import ConnectionError from ansible.module_utils.network.iosxr.iosxr import load_config, get_config, get_connection @@ -251,7 +251,7 @@ def copy_file_to_node(module): """ src = '/tmp/ansible_config.txt' file = open(src, 'wb') - file.write(module.params['src']) + file.write(to_bytes(module.params['src'], errors='surrogate_or_strict')) file.close() dst = '/harddisk:/ansible_config.txt'