30 lines
964 B
YAML
30 lines
964 B
YAML
---
|
|
- name: Apply Windows Updates
|
|
hosts: win_all
|
|
gather_facts: true
|
|
vars:
|
|
initial_reboot: |-
|
|
{{ 86400 <
|
|
(( ((ansible_date_time.date+" "+ansible_date_time.time)|to_datetime('%Y-%m-%d %H:%M:%S')) -
|
|
ansible_facts.lastboot|to_datetime('%Y-%m-%d %H:%M:%SZ')).total_seconds())|abs }}
|
|
tasks:
|
|
- name: Run Windows Updates
|
|
block:
|
|
- name: Install Updates And Reboot
|
|
ansible.windows.win_updates:
|
|
category_names:
|
|
- "*"
|
|
reboot: false
|
|
state: installed
|
|
become: true
|
|
become_method: ansible.builtin.runas
|
|
become_user: SYSTEM
|
|
register: update_results
|
|
|
|
- name: Reboot explicitly if required
|
|
ansible.windows.win_reboot:
|
|
reboot_timeout: 3600
|
|
post_reboot_delay: 120
|
|
test_command: 'powershell.exe -Command "Get-Service WinRM"'
|
|
when: update_results.reboot_required
|