Table of Contents

Automating Windows Updates with Ansible: A Comprehensive Guide

Keeping Windows systems up to date is crucial for maintaining security and stability. However, manually managing and installing updates across multiple systems can be a time-consuming and error-prone task. Fortunately, with the power of automation tools like Ansible, you can streamline the process and ensure that your systems are always up to date. In this article, we will explore how to automate Windows updates using Ansible and provide step-by-step instructions on setting up Ansible credentials and host files for all your targeted systems.

Why Automate Windows Updates with Ansible?

Automating Windows updates with Ansible offers several benefits:

  1. Time-saving: Instead of manually updating each system individually, you can automate the process and update multiple systems simultaneously, saving you valuable time and effort.

  2. Consistency: Automation ensures that all systems receive the same updates, reducing the risk of configuration drift and maintaining a consistent and secure environment.

  3. Efficiency: Ansible allows you to schedule updates at specific times, ensuring minimal disruption to your workflow and maximizing system availability.

  4. Scalability: Whether you have a handful of systems or a large infrastructure, Ansible scales effortlessly, making it an ideal choice for managing updates across any number of Windows systems.

Setting Up Ansible Credentials and Host Files

Before we dive into automating Windows updates, let’s first set up the necessary credentials and host files in Ansible.

  1. Installing Ansible: If you haven’t already, start by installing Ansible on your linux based ansible controller. You can follow the official Ansible documentation for detailed installation instructions: Ansible Installation

  2. Configuring Ansible Credentials: To automate updates on Windows systems, Ansible requires the appropriate credentials. Ensure that you have the necessary administrative credentials for each target system. You can store these credentials securely using Ansible’s Vault or a password manager of your choice.

  3. Creating the Ansible Hosts File: The Ansible hosts file defines the inventory of systems you want to manage. Create a text file called hosts and specify the target systems using their IP addresses or hostnames. For example:

  1. Defining Ansible Variables: To make the automation process more flexible, you can define variables in Ansible. For Windows updates, you might want to specify the desired update schedule or any additional configurations. Variables can be defined in the hosts file or separate variable files.

Automating Windows Updates Using Ansible

With the basic setup in place, let’s now explore how to automate Windows updates using Ansible.

See the role and files:

  1. Creating the Ansible Playbook: Ansible playbooks are YAML files that define a series of tasks to be executed on target systems. Create a new YAML file called update_windows.yml and define the necessary tasks.
- name: Install Security Patches for Windows
  hosts: windows
  gather_facts: false

    - name: Check for available updates
          - SecurityUpdates
        state: searched
      register: win_updates_result

    - name: Install security updates
          - SecurityUpdates
        state: installed
      when: win_updates_result.updates | length > 0

Save it in a file named install_security_patches.yml

This playbook first checks for available security updates using the win_updates module with the SecurityUpdates category. The result is registered in the win_updates_result variable. Then, the playbook proceeds to install the security updates if there are any available.

  1. Using Ansible Modules: Ansible provides various modules to interact with Windows systems. The win_updates module is specifically designed for managing Windows updates. Within your playbook, use this module to install updates, check for available updates, or reboot systems if required. Refer to the official Ansible documentation for detailed information on using the win_updates module: Ansible Windows Modules

  2. Running the Ansible Playbook: Once you have defined the tasks in your playbook, run it using the ansible-playbook command, specifying the playbook file and the target hosts. For example:

ansible-playbook -i hosts install_security_patches.yml
  1. Schedule Regular Execution: To ensure that updates are applied consistently, you can schedule the execution of the Ansible playbook at regular intervals. Tools like cron (on Linux) or Task Scheduler (on Windows) can be used to automate this process. You should use cron to for this specifically as the playbook is launched from an linux based ansible controller.

Open crontab

   crontab -e

Add the following line after you modify it

0 3 * * * ansible-playbook -i /path/to/hosts /path/to/playbook.yml


Automating Windows updates with Ansible can greatly simplify the management of updates across your infrastructure. By following the steps outlined in this article, you can set up Ansible credentials, define host files, and create playbooks to automate the update process. Embracing automation not only saves time but also ensures that your Windows systems are up to date, secure, and operating at their best.

Remember to stay informed about relevant government regulations such as the NIST Cybersecurity Framework or ISO/IEC 27001 , which provide guidelines and best practices for maintaining a secure and compliant environment.