ansible - Ansible - win_update 从输出中过滤 kb
问题描述
我们使用 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
解决方案
推荐阅读
- python-3.x - Python - Web Scraper - 不涨价
- yii2 - Yii2 pjax 调用导致反序列化错误
- javascript - Javascript 中未调用覆盖函数(严格模式)
- android - 无法解决 Qualtrics 初始化中的错误
- regex - 如何在 MongoDB 中使用正则表达式在字符串末尾搜索单词?
- amazon-web-services - AWS boto3。如何将 EC2 实例启动到给定集群中?
- sql - Hive 使用分区连接表
- php - 如何使用 Carbon/Laravel 检查年份是否已过?
- python - 删除嵌入消息而不删除文本消息 discord.py
- python - 有没有办法从错误发生的地方继续而不是重复?