首页 > 解决方案 > 在 Ansible 中排除 Windows 更新

问题描述

我有一个在 Windows 上安装关键和安全更新的 Ansible 剧本:

---
- name: Install all security, critical updates
  win_updates:
    category_names:
      - SecurityUpdates
      - CriticalUpdates
    reject_list:
    reboot: yes
    reboot_timeout: 900

我想对 playbook 进行微调,以拒绝名称中包含 Preview、* Preview*、* VMware* 和 * Driver* 的任何更新。我知道该reject_list参数允许您将更新标题用作正则表达式,但我不确定对于我希望更新拒绝的特定名称如何表达这一点。

标签: ansibleyaml

解决方案


根据https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_updates_module.html ,根据 PowerShell 正则表达式规则,每个条目可以是知识库文章或更新标题作为正则表达式。在此网站https://regexr.com/3c0lf上对 powershell 正则表达式和测试用例进行了快速研究。我相信以下语法应该可以工作,但我自己没有尝试过。

reject_list:
    - '.*Preview.*'
    - '.*VMware.*'
    - '.*Driver.*'


推荐阅读