Ansible-输出中的win_update过滤器kb

时间:2019-12-05 10:28:27

标签: ansible

我们使用ansible和win_update模块更新Windows服务器。现在我们要生成一个日志,其中包含哪个服务器下载了哪个更新的信息(kb号)。我可以从输出中成功过滤掉kb编号,但是当我将kb编号写入日志时,ansible将为每个kb编号写入新行。所以看起来像这样:

Host:ServerA ,IP:10.10.10.10 ,Downloaded Updates:2 ,KB-Number:[u4525236]
Host:ServerA ,IP:10.10.10.10 ,Downloaded Updates:2 ,KB-Number:[u2267602]

但是我想要以下结果:

Host:ServerA ,IP:10.10.10.10 ,Downloaded Updates:2 ,KB-Number:[u4525236][u2267602]

我该如何实现?

这是win_update返回的示例:

[ServerA] => {
    "changed": false,
    "filtered_updates": {},
    "found_update_count": 2,
    "installed_update_count": 0,
    "reboot_required": false,
    "updates": {
        "1277d483-7f10-45e5-9037-739e191b6151": {
            "categories": [
                "Definition Updates",
                "Windows Defender"
            ],
            "id": "1277d483-7f10-45e5-9037-739e191b6151",
            "installed": false,
            "kb": [
                "2267602"
            ],
            "title": "Security Intelligence-Update für Windows Defender Antivirus - KB2267602 (Version 1.305.3389.0)"
        },
        "36511ef0-14b8-4883-a0bc-49c047981b50": {
            "categories": [
                "Security Updates",
                "Windows Server 2016"
            ],
            "id": "36511ef0-14b8-4883-a0bc-49c047981b50",
            "installed": false,
            "kb": [
                "4525236"
            ],
            "title": "2019-11 Kumulatives Update für Windows Server 2016 für x64-basierte Systeme (KB4525236)"
        }
    }
}

我在剧本中有以下任务,以过滤kb并将其写入日志。我在“值”中注册了win_update返回。

- name: Creating Log
      shell: echo Host:{{inventory_hostname}} ,IP:{{ ansible_host }} ,Downloaded Updates:{{ values.found_update_count }} ,KB-Number:{{ item.value.kb }} >> log.csv
      with_items:
        - "{{ values.updates | dict2items }}"
      delegate_to: localhost

0 个答案:

没有答案