ãã®è¨äºã¯ããRed Hat Advent Calendar 2023ã20æ¥ç®ã®è¨äºã§ãã
Windowsã®æååãåé¡
Ansibleã§Windowsãã¼ãã管çãã¦ããã¨ãç¹ã«win_shellã¢ã¸ã¥ã¼ã«ã§ã³ãã³ããå®è¡ããéãªã©ã®å®è¡çµæãæææååããã¦ãã¾ãã±ã¼ã¹ãããã¾ãããããªã£ã¦ãã¾ãã¨ãå®è¡çµæãæ£ããèªã¿åãããWindowsèªååã®éå£ã¨ãªã£ã¦ãã¾ãã¾ãã
ãªãæååããçºçããã®ã
Ansibleã§ã¯ãWinRMçµç±ã§Windowsã«æ¥ç¶ãã¾ããããã®éã®æ°è¦ã»ãã·ã§ã³ã«å¯¾ãã¦ã¯UTF-8ãå©ç¨ããããæå®ãã¦æ¥ç¶ãã¾ããããã¯ãé常ã®Windowsã¢ã¸ã¥ã¼ã«ã®å®è¡ã§ããã°åé¡ã¯çºçãã¾ããã
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/winrm.py#L474-L477
# open the shell from connect so we know we're able to talk to the server if not self.shell_id: self.shell_id = protocol.open_shell(codepage=65001) # UTF-8 display.vvvvv('WINRM OPEN SHELL: %s' % self.shell_id, host=self._winrm_host)
ããããShift_JISã®ãããªå¥ã®æåã¨ã³ã³ã¼ãã£ã³ã°ãããã©ã«ãã§å©ç¨ãã¦ãããwin_shellãwin_commandã®ãããªPowerShellä¸ã§ã³ãã³ããå®è¡ããã¢ã¸ã¥ã¼ã«ãå©ç¨ããå ´åãå®è¡ãããã³ãã³ãã¯ããã©ã«ãã®æåã¨ã³ã³ã¼ãã£ã³ã°ãå©ç¨ãããããå®è¡çµæã¯Shift_JISã§è¿å´ããã¾ãããã®ãããAnsibleã«æ¸¡ãããå®è¡çµæã¯UTF-8ã§ãªããªããæååããçºçãã¾ãã
対å¦æ¹æ³
ä¸è¨ã®ãããªæ³å®ãã¦ããªãæååãã«å¯¾å¦ãããããwin_shellã¢ã¸ã¥ã¼ã«ãªã©ã§ã¯ãoutput_encoding_overrideããªãã·ã§ã³ãå©ç¨ã§ãã¾ãã
ansible.windows.win_shell module – Execute shell commands on target hosts — Ansible Documentation
ãã®ãªãã·ã§ã³ã§ã¯ãè¿å´ãããå®è¡çµæãæå®ããæåã¨ã³ã³ã¼ãã£ã³ã°ã§ä¸æ¸ããã¦è§£éãã¾ããåºæ¬çã«ãWindowsä¸ã§ [System.Text.Encoding]::GetEncodings()
ãå®è¡ããéã«è¿å´ããããNameãã®æåã¨ã³ã³ã¼ãã£ã³ã°(Shift_JISã§ããã°shift_jis)ãæå®ã§ãã¾ãã
PS C:\Users\hiyoko> [System.Text.Encoding]::GetEncodings() CodePage Name DisplayName -------- ---- ----------- 37 IBM037 IBM EBCDIC (US - ã«ãã) 437 IBM437 OEM ã¢ã¡ãªã«åè¡å½ 500 IBM500 IBM EBCDIC (ã¤ã³ã¿ã¼ãã·ã§ãã«) 708 ASMO-708 ã¢ã©ãã¢èª (ASMO 708) 720 DOS-720 ã¢ã©ãã¢èª (DOS) 737 ibm737 ã®ãªã·ã£èª (DOS) 775 ibm775 ãã«ãè¨èª (DOS) 850 ibm850 西ã¨ã¼ãããè¨èª (DOS) 852 ibm852 ä¸å¤®ã¨ã¼ãããè¨èª (DOS) 855 IBM855 OEM ããªã« 857 ibm857 ãã«ã³èª (DOS) 858 IBM00858 OEM ãã«ããªã³ã¬ã« ã©ãã³ I 860 IBM860 ãã«ãã¬ã«èª (DOS) 861 ibm861 ã¢ã¤ã¹ã©ã³ãèª (DOS) 862 DOS-862 ããã©ã¤èª (DOS) 863 IBM863 ãã©ã³ã¹èª (ã«ãã) (DOS) 864 IBM864 ã¢ã©ãã¢èª (864) 865 IBM865 å欧 (DOS) 866 cp866 ããªã«è¨èª (DOS) 869 ibm869 ã®ãªã·ã£èª, Modern (DOS) 870 IBM870 IBM EBCDIC (å¤å½èªã©ãã³ 2) 874 windows-874 ã¿ã¤èª (Windows) 875 cp875 IBM EBCDIC (ã®ãªã·ã£èª Modern) 932 shift_jis æ¥æ¬èª (ã·ãã JIS) 936 gb2312 ç°¡ä½åä¸å½èª (GB2312) 949 ks_c_5601-1987 éå½èª 950 big5 ç¹ä½åä¸å½èª (Big5) 1026 IBM1026 IBM EBCDIC (ãã«ã³èªã©ãã³ 5) 1047 IBM01047 IBM ã©ãã³-1 1140 IBM01140 IBM EBCDIC (US - ã«ãã - ã¨ã¼ããã) 1141 IBM01141 IBM EBCDIC (ãã¤ã - ã¨ã¼ããã) 1142 IBM01142 IBM EBCDIC (ãã³ãã¼ã¯ - ãã«ã¦ã§ã¼ - ã¨ã¼ããã) 1143 IBM01143 IBM EBCDIC (ãã£ã³ã©ã³ã - ã¹ã¦ã§ã¼ãã³ - ã¨ã¼ããã) 1144 IBM01144 IBM EBCDIC (ã¤ã¿ãªã¢ - ã¨ã¼ããã) 1145 IBM01145 IBM EBCDIC (ã¹ãã¤ã³ - ã¨ã¼ããã) 1146 IBM01146 IBM EBCDIC (UK - ã¨ã¼ããã) 1147 IBM01147 IBM EBCDIC (ãã©ã³ã¹ - ã¨ã¼ããã) 1148 IBM01148 IBM EBCDIC (ã¤ã³ã¿ã¼ãã·ã§ãã« - ã¨ã¼ããã) 1149 IBM01149 IBM EBCDIC (ã¢ã¤ã¹ã©ã³ãèª - ã¨ã¼ããã) 1200 utf-16 Unicode 1201 utf-16BE Unicode (Big-Endian) 1250 windows-1250 ä¸å¤®ã¨ã¼ãããè¨èª (Windows) 1251 windows-1251 ããªã«è¨èª (Windows) 1252 Windows-1252 西ã¨ã¼ãããè¨èª (Windows) 1253 windows-1253 ã®ãªã·ã£èª (Windows) 1254 windows-1254 ãã«ã³èª (Windows) 1255 windows-1255 ããã©ã¤èª (Windows) 1256 windows-1256 ã¢ã©ãã¢èª (Windows) 1257 windows-1257 ãã«ãè¨èª (Windows) 1258 windows-1258 ãããã èª (Windows) 1361 Johab éå½èª (Johab) 10000 macintosh 西ã¨ã¼ãããè¨èª (Mac) 10001 x-mac-japanese æ¥æ¬èª (Mac) 10002 x-mac-chinesetrad ç¹ä½åä¸å½èª (Mac) 10003 x-mac-korean éå½èª (Mac) 10004 x-mac-arabic ã¢ã©ãã¢èª (Mac) 10005 x-mac-hebrew ããã©ã¤èª (Mac) 10006 x-mac-greek ã®ãªã·ã£èª (Mac) 10007 x-mac-cyrillic ããªã«è¨èª (Mac) 10008 x-mac-chinesesimp ç°¡ä½åä¸å½èª (Mac) 10010 x-mac-romanian ã«ã¼ããã¢èª (Mac) 10017 x-mac-ukrainian ã¦ã¯ã©ã¤ãèª (Mac) 10021 x-mac-thai ã¿ã¤èª (Mac) 10029 x-mac-ce ä¸å¤®ã¨ã¼ãããè¨èª (Mac) 10079 x-mac-icelandic ã¢ã¤ã¹ã©ã³ãèª (Mac) 10081 x-mac-turkish ãã«ã³èª (Mac) 10082 x-mac-croatian ã¯ãã¢ãã¢èª (Mac) 12000 utf-32 Unicode (UTF-32) 12001 utf-32BE Unicode (UTF-32 ããã° ã¨ã³ãã£ã¢ã³) 20000 x-Chinese-CNS ç¹ä½åä¸å½èª (CNS) 20001 x-cp20001 TCA å°æ¹¾ 20002 x-Chinese-Eten ç¹ä½åä¸å½èª (Eten) 20003 x-cp20003 IBM5550 å°æ¹¾ 20004 x-cp20004 TeleText å°æ¹¾ 20005 x-cp20005 Wang å°æ¹¾ 20105 x-IA5 西ã¨ã¼ãããè¨èª (IA5) 20106 x-IA5-German ãã¤ãèª (IA5) 20107 x-IA5-Swedish ã¹ã¦ã§ã¼ãã³èª (IA5) 20108 x-IA5-Norwegian ãã«ã¦ã§ã¼èª (IA5) 20127 us-ascii US-ASCII 20261 x-cp20261 T.61 20269 x-cp20269 ISO-6937 20273 IBM273 IBM EBCDIC (ãã¤ã) 20277 IBM277 IBM EBCDIC (ãã³ãã¼ã¯ - ãã«ã¦ã§ã¼) 20278 IBM278 IBM EBCDIC (ãã£ã³ã©ã³ã - ã¹ã¦ã§ã¼ãã³) 20280 IBM280 IBM EBCDIC (ã¤ã¿ãªã¢) 20284 IBM284 IBM EBCDIC (ã¹ãã¤ã³) 20285 IBM285 IBM EBCDIC (UK) 20290 IBM290 IBM EBCDIC (æ¥æ¬èªã«ã¿ã«ã) 20297 IBM297 IBM EBCDIC (ãã©ã³ã¹) 20420 IBM420 IBM EBCDIC (ã¢ã©ãã¢èª) 20423 IBM423 IBM EBCDIC (ã®ãªã·ã£èª) 20424 IBM424 IBM EBCDIC (ããã©ã¤èª) 20833 x-EBCDIC-KoreanExtended IBM EBCDIC (éå½èª Extended) 20838 IBM-Thai IBM EBCDIC (ã¿ã¤èª) 20866 koi8-r ããªã«è¨èª (KOI8-R) 20871 IBM871 IBM EBCDIC (ã¢ã¤ã¹ã©ã³ãèª) 20880 IBM880 IBM EBCDIC (ããªã«è¨èª - ãã·ã¢èª) 20905 IBM905 IBM EBCDIC (ãã«ã³èª) 20924 IBM00924 IBM ã©ãã³-1 20932 EUC-JP æ¥æ¬èª (JIS 0208-1990 ããã³ 0212-1990) 20936 x-cp20936 ç°¡ä½åä¸å½èª (GB2312-80) 20949 x-cp20949 éå½èª Wansung 21025 cp1025 IBM EBCDIC (ããªã«è¨èª ã»ã«ã㢠- ãã«ã¬ãªã¢) 21866 koi8-u ããªã«è¨èª (KOI8-U) 28591 iso-8859-1 西ã¨ã¼ãããè¨èª (ISO) 28592 iso-8859-2 ä¸å¤®ã¨ã¼ãããè¨èª (ISO) 28593 iso-8859-3 ã©ãã³ 3 (ISO) 28594 iso-8859-4 ãã«ãè¨èª (ISO) 28595 iso-8859-5 ããªã«è¨èª (ISO) 28596 iso-8859-6 ã¢ã©ãã¢èª (ISO) 28597 iso-8859-7 ã®ãªã·ã£èª (ISO) 28598 iso-8859-8 ããã©ã¤èª (ISO-Visual) 28599 iso-8859-9 ãã«ã³èª (ISO) 28603 iso-8859-13 ã¨ã¹ããã¢èª (ISO) 28605 iso-8859-15 ã©ãã³ 9 (ISO) 29001 x-Europa ã¨ã¼ããã 38598 iso-8859-8-i ããã©ã¤èª (ISO-Logical) 50220 iso-2022-jp æ¥æ¬èª (JIS) 50221 csISO2022JP æ¥æ¬èª (JIS 1 ãã¤ã ã«ã¿ã«ãå¯) 50222 iso-2022-jp æ¥æ¬èª (JIS 1 ãã¤ã ã«ã¿ã«ãå¯ - SO/SI) 50225 iso-2022-kr éå½èª (ISO) 50227 x-cp50227 ç°¡ä½åä¸å½èª (ISO-2022) 51932 euc-jp æ¥æ¬èª (EUC) 51936 EUC-CN ç°¡ä½åä¸å½èª (EUC) 51949 euc-kr éå½èª (EUC) 52936 hz-gb-2312 ç°¡ä½åä¸å½èª (HZ) 54936 GB18030 ç°¡ä½åä¸å½èª (GB18030) 57002 x-iscii-de ISCII ãããã¬ãªæå 57003 x-iscii-be ISCII ãã³ã¬ã«èª 57004 x-iscii-ta ISCII ã¿ãã¼ã«èª 57005 x-iscii-te ISCII ãã«ã°èª 57006 x-iscii-as ISCII ã¢ããµã èª 57007 x-iscii-or ISCII ãªãªã¤ã¼èª 57008 x-iscii-ka ISCII ã«ãã©èª 57009 x-iscii-ma ISCII ãã©ã¤ã©ã èª 57010 x-iscii-gu ISCII ã°ã¸ã£ã©ã¼ãèª 57011 x-iscii-pa ISCII ãã³ã¸ã£ãèª 65000 utf-7 Unicode (UTF-7) 65001 utf-8 Unicode (UTF-8)
ããå®è¡çµæãæååããã¦ãã¾ã£ã¦å°ã£ã¦ããæã«ã¯ãä¸è¨ãªãã·ã§ã³ã試ãã¦ã¿ã¦ãã ããã
Happy Automationï¼