ansible - Ansible如何获取windows更新kb数
问题描述
我正在尝试使用 ansible 获取挂起的已安装 Windows 更新 kb。
- name: Check for missing updates.
win_updates:
state: searched
category_names: "{{ win_updates_categories }}"
register: update_count
ignore_errors: yes
- debug: msg="{{ update_count.updates.kb }}"
但是运行出错,谁能帮帮我,谢谢!
这是寄存器更新的输出
- debug:
var: update_count
"update_count": {
"changed": false,
"failed": false,
"filtered_updates": {},
"found_update_count": 1,
"installed_update_count": 0,
"reboot_required": false,
"updates": {
"67eab6a6-099b-42c5-86ce-63681f58ebd2": {
"categories": [
"Security Updates",
"Windows Server 2016"
],
"id": "67eab6a6-099b-42c5-86ce-63681f58ebd2",
"installed": false,
"kb": [
"4593226"
],
}
}
}
}
如果我只想显示 kb 信息,这是错误
- debug:
var: update_count.updates.kb
"update_count.updates.kb": "VARIABLE IS NOT DEFINED!"
解决方案
请看下面,我使用 {{ item.value.id }} 来获取 ID 值(最后一个任务),如果它们不止一个,则将它们保存在一个数组中,同样的方式你应该能够检索 KB。希望这能解释
仅安装关键更新 - 必要时重新启动
- name: install category critical updates only
win_updates:
category_names: ['CriticalUpdates']
server_selection: windows_update
state: installed
ignore_errors: yes
register: CriticalUpdateResults
- name: Postgres Column Values assigned
set_fact: UpdateCategory="{{ CriticalUpdateResults }}"
- name: CriticalUpdates Category assigned
set_fact: PatchCategory="CriticalUpdates"
- name: UpdatesArray assigned space
set_fact:
UpdatesArray: ""
- name: UpdatesArray assigned None if no update count
set_fact:
UpdatesArray: "None"
when: UpdateCategory.found_update_count == 0
- name: Updates Array assigned
set_fact:
UpdatesArray: "{{ UpdatesArray }} {{ **item.value.id** }}"
with_items:
- "{{ UpdateCategory.updates | dict2items }}"
when: UpdateCategory.found_update_count != 0
推荐阅读
- vue.js - Vue,如果我选择一个选项,如何得到一个空行?
- spring-boot - 如何使用两个数据源(MapRepository 和 H2 JPARepository)设置 Spring Boot?
- javascript - 创建没有循环的二维数组 - JavaScript
- flutter - 来自有状态父级的无状态小部件 dropdownButton 的 Setstate
- python - RuntimeError:在以下位置忽略异常:
我正在使用aiohttp、asyncio和codetiming来发出并发请求。我最近将 Python 升级到了 3.9.0 版,我收到了 RuntimeError: Event loop is closed after the p
- javascript - 如何将 html/js 项目包含到 vue 项目中?
- git - 删除一个分支会删除它的子分支吗?
- java - Camera2:使 SurfaceView 方面适合填充(scaleType CENTER_CROP)
- sql - 所有旅行产生的总收入是多少?票价存储在列 total_amount
- django - 从父类和表单继承,然后我想要一个列表视图