繁体   English   中英

使用Ansible的win_update模块时编码西里尔字母符号错误

[英]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种方式:

  1. 在Windows主机上设置默认的Powershell输出编码
  2. 在文件ansible / modules / windows / win_updates.ps1中的ansible源代码中,添加以下代码行:

    [控制台] :: OutputEncoding = [System.Text.Encoding] :: GetEncoding(“ utf-8”)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM