1

we update our windows servers with ansible and the win_update module. Now we want to generate a log with the information which server downloaded which update (kb number). I can successfully filter the kb numbers from the output, but when I am writing the kb numbers to the log, ansible writes for every kb number a new line. So it looks like this:

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]

But I want following result:

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

How can i achive this?

This is an example return from 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)"
        }
    }
}

And I have following task in my playbook to filter the kb and write it to the log. I register the win_update return in "values".

- 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
baumi
  • 11
  • 4
  • see eg https://stackoverflow.com/questions/47244834/how-to-join-a-list-of-strings-in-ansible it may be more readbable to create the list of kb numbers before creating the log line – 9bO3av5fw5 Dec 05 '19 at 11:24
  • @9bO3av5fw5 Thanks for the advice, but unfortunatley it didnt work. I am not able to save all kb-numbers in my list. Just the kb of the last updated is saved in my list. – baumi Dec 09 '19 at 14:53

0 Answers0