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