[英]Bad encode cyrillic symbols when use win_update module of ansible
使用ansible的win_update模塊
劇本:
- name: Update
tasks:
- name: Check updates
register: result
win_updates:
state: searched
- debug: var=result
hosts: windows
主持人:
all:
children:
windows:
hosts:
somehost:
Group_vars:
ansible_user: someuser
ansible_password: somepassword
ansible_connection: winrm
ansible_port: 5986
ansible_winrm_server_cert_validation: ignore
在調試中得到結果:
ok: [somehost] => {
"result": {
"changed": false,
"failed": false,
"filtered_updates": {},
"found_update_count": 2,
"installed_update_count": 0,
"reboot_required": false,
"updates": {
"8fde14d1-2fd6-4705-b2ab-b2aaf1aa7a05": {
"id": "8fde14d1-2fd6-4705-b2ab-b2aaf1aa7a05",
"installed": false,
"kb": [
"4054518"
],
"title": "��������� ����� ��ࠢ����� ����⢠ ��⥬� ������᭮�� ��� ��⥬ Windows 7 �� ���� ����� x64 (KB4054518), 12 2017 �."
},
"bc3e1d56-c863-467e-a13d-77460eff0dcc": {
"id": "bc3e1d56-c863-467e-a13d-77460eff0dcc",
"installed": false,
"kb": [
"890830"
],
"title": "�।�⢮ 㤠����� �।������ �ணࠬ� ��� ������� x64: ���� 2018 �. (KB890830)"
}
}
}
}
我應該在哪里更改普通Windows更新標題名稱的代碼? win_update powershell腳本或winrm或其他地方
更新:不幸的是,當我使用穩定版本的ansible(2.4.3.0)時,出現錯誤:
ansible win10.dev -i hosts -m win_updates -a 'state=searched'
win10.dev | FAILED! => {
"changed": false,
"module_stderr": "An error occurred while creating the pipeline.\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException\r\n + FullyQualifiedErrorId : RuntimeException\r\n \r\nTimed out waiting for scheduled task to start\r\nAt line:334 char:9\r\n+ Throw \"Timed out waiting for scheduled task to start\"\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : OperationStopped: (Timed out waiti...d task to start:String) [], RuntimeException\r\n + FullyQualifiedErrorId : Timed out waiting for scheduled task to start\r\n \r\n\r\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
在這個線程中( https://github.com/ansible/ansible/issues/25298 )我沒有找到決定,所以我不得不使用ansible存儲庫的@devel分支。
一切都應該開箱即用。 它是UTF-8
。 確保您當前的外殼程序已啟用UTF。
Ansible盒子:
$ locale
LANG="ru_RU.UTF-8"
...
$ ansible --version
ansible 2.4.2.0
...
$ ansible winsrv -m win_updates -a 'state=searched'
...
"title": "Накопительное обновление для Windows Server 2016 для систем на базе процессоров x64, 2018 03 (KB4088787)"
...
"title": "Обновление для Windows Server 2016 для систем на базе процессоров x64 (KB4049065), 11.2017"
...
視窗框:
PS> [cultureinfo]::InstalledUICulture
LCID Name DisplayName
---- ---- -----------
1049 ru-RU Русский (Россия)
決斷
Powershell具有默認的輸出編碼設置。 所以我所有的Windows主機都有
>[Console]::OutputEncoding
IsSingleByte : True
BodyName : cp866
EncodingName : Кириллица (DOS)
HeaderName : cp866
WebName : cp866
WindowsCodePage : 1251
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : False
IsMailNewsSave : False
EncoderFallback : System.Text.InternalEncoderBestFitFallback
DecoderFallback : System.Text.InternalDecoderBestFitFallback
IsReadOnly : True
CodePage : 866
2種方式:
在文件ansible / modules / windows / win_updates.ps1中的ansible源代碼中,添加以下代碼行:
[控制台] :: OutputEncoding = [System.Text.Encoding] :: GetEncoding(“ utf-8”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.