Skip to content

Instantly share code, notes, and snippets.

@elordahl
Last active November 17, 2023 16:35
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save elordahl/df739b91dbd77199e6913e11e9136186 to your computer and use it in GitHub Desktop.
Save elordahl/df739b91dbd77199e6913e11e9136186 to your computer and use it in GitHub Desktop.
Ansible playbook to run Windows Update and restart, if required
---
# Ansible playbook to run Windows Update and restart, if required
#
# http://docs.ansible.com/ansible/win_updates_module.html
# https://docs.ansible.com/ansible/win_reboot_module.html
- name: Windows Update
hosts: all
gather_facts: false
tasks:
- name: Running Windows Update
win_updates:
category_names: ['SecurityUpdates','CriticalUpdates','UpdateRollups', 'Updates', 'DefinitionUpdates']
register: result
# output results
- debug: var=result
# reboot only if required
- win_reboot:
when: result.reboot_required
@coom
Copy link

coom commented Jul 11, 2018

You can also use :

- name:  Windows Update
  hosts: all
  gather_facts: false
  tasks:
    - name: Running Windows Update
      win_updates:
        category_names: ['SecurityUpdates','CriticalUpdates','UpdateRollups', 'Updates', 'DefinitionUpdates']
        reboot: yes

;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment