1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
From fb6123b5419dee8de0bd739383ee1c67ad596216 Mon Sep 17 00:00:00 2001
From: Lee Garrett <lgarrett@rocketjump.eu>
Date: Fri, 1 Sep 2023 14:35:15 +0200
Subject: [PATCH 1/2] Fix encoding errors on Windows guests (fixes: #156)
On Windows guests the default encoding will be set to whatever
default legacy encoding, not utf-8. This issue isn't apparent on English locale
Windows guests, as there the encodings (ISO-8859-1, utf-8) happen to coincide.
However, on e.g. German Windows guests this will cause an encoding error when
reading any output from there.
This patch ensures that the proper encoding is set on every command.
---
plugins/connection/libvirt_qemu.py | 4 ++++
1 file changed, 4 insertions(+)
--- a/ansible_collections/community/libvirt/plugins/connection/libvirt_qemu.py
+++ b/ansible_collections/community/libvirt/plugins/connection/libvirt_qemu.py
@@ -164,6 +164,10 @@
# utf-8, this must be done via chcp to get utf-8 (65001)
cmd = ' '.join(["chcp.com", "65001", self._shell._SHELL_REDIRECT_ALLNULL, self._shell._SHELL_AND, cmd])
+ # Make sure our first command is to set the console encoding to
+ # utf-8, this must be done via chcp to get utf-8 (65001)
+ cmd = ' '.join(["chcp.com", "65001", self._shell._SHELL_REDIRECT_ALLNULL, self._shell._SHELL_AND, cmd])
+
# Generate powershell commands
cmd_args_list = self._shell._encode_script(cmd, as_list=True, strict_mode=False, preserve_rc=False)
--- /dev/null
+++ b/ansible_collections/community/libvirt/changelogs/fragments/156_fix_windows_encoding.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - libvirt_qemu - fix encoding errors on Windows guests for non-ASCII return values (https://github.com/ansible-collections/community.libvirt/pull/157)
|