# Orchestrate updates, reboots and maintenance windows with Ansible

Source: https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows
Language: en
Published: 2026-10-12
Updated: 2026-11-20

How to prepare updates, process hosts in batches, verify reboots and validate services after restart.

## Why updates deserve their own playbook

Update automation should not disappear inside a baseline role. Updates carry different risk: repositories change, reboots may be required, services must come back and maintenance windows must not be exceeded accidentally.

This part deliberately stays generic. It is not about SUSE Multi-Linux Manager, FreeIPA or Proxmox, but about a reusable Ansible pattern for Linux updates. Specialist cases belong in their own series.

## Target design

- Limit the target group before changing packages.
- Prepare changes with check mode.
- Process hosts in small batches.
- Detect or trigger reboots deliberately.
- Verify connectivity, services and baseline state after reboot.

## Inventory groups for maintenance windows

```yaml
all:
  children:
    linux:
      children:
        maintenance_window_a:
          hosts:
            sles16-client01.example.test:
        maintenance_window_b:
          hosts:
            rocky10-client01.example.test:
```

## Playbook with batch processing

```yaml
# playbooks/linux-update.yaml
- name: Patch Linux systems in controlled batches
  hosts: linux
  become: true
  gather_facts: true
  serial: 2
  max_fail_percentage: 20

  pre_tasks:
    - name: Confirm selected hosts
      ansible.builtin.debug:
        msg: "Updating {{ inventory_hostname }} in {{ ansible_play_hosts_all | length }} selected hosts"

  tasks:
    - name: Refresh package metadata and install available updates
      ansible.builtin.package:
        name: '*'
        state: latest

    - name: Reboot host when maintenance window allows it
      ansible.builtin.reboot:
        reboot_timeout: 900
        test_command: whoami
      when: linux_updates_allow_reboot | default(false)

  post_tasks:
    - name: Verify host is reachable after update
      ansible.builtin.ping:
```

## Variables instead of spontaneous decisions

```yaml
# inventories/lab/group_vars/maintenance_window_a.yaml
linux_updates_allow_reboot: true
linux_updates_expected_services:
  - sshd
  - chronyd
```

## Service validation after update

```yaml
- name: Verify expected services are running
  ansible.builtin.service_facts:

- name: Assert expected services are active
  ansible.builtin.assert:
    that:
      - ansible_facts.services[item + '.service'].state == 'running'
    fail_msg: "Expected service {{ item }} is not running"
  loop: "{{ linux_updates_expected_services | default([]) }}"
```

## Acceptance run

```bash
ansible-playbook -i inventories/lab/hosts.yaml playbooks/linux-update.yaml --syntax-check
ansible-playbook -i inventories/lab/hosts.yaml playbooks/linux-update.yaml --limit maintenance_window_a --check --diff
ansible-playbook -i inventories/lab/hosts.yaml playbooks/linux-update.yaml --limit maintenance_window_a
ansible-playbook -i inventories/lab/hosts.yaml playbooks/linux-update.yaml --limit maintenance_window_a --check --diff
```

## Acceptance table

```markdown
| Area | Check | Result |
| --- | --- | --- |
| Targeting | --limit selects only the maintenance window | PASS |
| Simulation | check mode shows planned package changes | PASS |
| Batch | serial limits parallel hosts | PASS |
| Reboot | reboot runs only when the window allows it | PASS |
| Connectivity | host is reachable after reboot | PASS |
| Services | expected services run after update | PASS |
```

## Limits

This pattern does not replace central patch management or package approval. It describes the technical workflow that can later be connected to SUSE Multi-Linux Manager, repositories, change management or CI/CD.

## Sources and further documentation

The examples follow official Ansible modules for package management, reboot, rolling updates, check mode and diff mode.

## Hero image

[![Ansible logo.](https://forgeone.solutions/media/Ansible_Logo.webp)](https://forgeone.solutions/media/Ansible_Logo.webp)

## Author

Mathias Rumbold

## Category

- [Ansible & Automation](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?category=ansible-automation)
- [Enterprise Linux](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?category=enterprise-linux)

## Tags

- [Ansible](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?tags=ansible)
- [Ansible Roles](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?tags=ansible-roles)
- [Automation](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?tags=automation)
- [Linux](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?tags=linux)
- [Linux Management](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?tags=linux-management)
- [Enterprise Linux](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows?tags=enterprise-linux)

## Ansible automation step by step

This series deliberately stays generic: Ansible fundamentals, repository structure, roles, Vault, Linux baselines, updates, quality checks, CI and AWX. Domain topics such as IdM, FreeIPA, Proxmox or SUSE Multi-Linux Manager are covered in their own specialist series.

1. [Install Ansible and create your first playbooks](https://forgeone.solutions/en/tech/install-ansible-and-create-your-first-playbooks)
2. [Ansible inventories, roles and Vault in practice](https://forgeone.solutions/en/tech/ansible-inventories-roles-vault-manage-linux-systems-reproducibly)
3. [Roll out a Linux baseline with Ansible](https://forgeone.solutions/en/tech/ansible-linux-baseline-packages-services-ssh-acceptance)
4. [Orchestrate updates, reboots and maintenance windows with Ansible (current part)](https://forgeone.solutions/en/tech/ansible-orchestrate-updates-reboots-maintenance-windows)
5. [Test, lint and validate Ansible roles in CI](https://forgeone.solutions/en/tech/ansible-test-lint-validate-roles-ci)
6. [Version, release and change Ansible repositories traceably](https://forgeone.solutions/en/tech/ansible-version-release-change-repositories-traceably)
7. [Position AWX for repeatable execution, credentials and job templates](https://forgeone.solutions/en/tech/awx-ansible-jobs-credentials-job-templates)

## Further content

- [Ansible](https://forgeone.solutions/en/products/ansible)
