DEV Community

Oleksandr Kuryzhev
Oleksandr Kuryzhev

Posted on Originally published at kuryzhev.cloud

Ubuntu 26.04 Upgrade with Ansible: Migrate 24.04 Fleets Safely

Originally published on kuryzhev.cloud


You have forty Ubuntu 24.04 servers in an inventory, a change window on Thursday, and a manager asking whether the Ubuntu 26.04 upgrade can be "just a playbook run". It can, if you treat it as a staged migration and not a bulk apt upgrade. This runbook shows how to drive do-release-upgrade from Ansible one host at a time, with checks before and after each step.

The timing matters now. Ubuntu 26.04 LTS was released on 2026-04-23, and the current point release is 26.04.1, according to the Ubuntu release cycle page. Ubuntu normally offers LTS-to-LTS upgrades to servers only once the first point release is out, so the supported upgrade path should now be open. Verify that on your own hosts with the check task shown below. It fails if no upgrade is offered yet.

Short answer: bring every host to fully patched 24.04 and take a snapshot. Then run a serial: 1 playbook that wraps do-release-upgrade in async, reboots, and asserts 26.04. Upgrade a canary first. Where you can, rebuild stateless hosts from a fresh 26.04 image instead. In-place upgrades carry the risk, and rebuilding avoids most of it.

What changed and who is affected

Every 24.04 host that you want on a supported LTS beyond its current cycle is affected. Ubuntu 24.04 is still supported, so this is a planned migration, not an emergency. Check the support dates for both releases on the release cycle page before you commit to a deadline.

The groups that need the most care:

  • Hosts with third-party apt repositories (Docker, PostgreSQL PGDG, Grafana, Jenkins). The upgrader disables third-party sources, and you must re-enable them for the new release.
  • Stateful hosts such as databases, where a major library and service-version jump happens in the same reboot.
  • Jenkins agents. Jenkins LTS 2.555.1+ requires Java 21 or 25 on the controller and on every agent JVM. Confirm that the Java package your agents use exists on the new release (upgrade guide).
  • Control nodes. ansible-core 2.22 is the current release (2.22.0, released 2026-11-02). Check the Ansible documentation for the supported target-Python matrix. A new release usually ships a newer system Python, and that is the interpreter Ansible uses on the target.

Read the official 26.04 release notes for removed or replaced packages before you start. This article does not list package-level changes, because they are version-specific and you should take them from Canonical.

Before/after config

The common failure is a playbook set that hardcodes the old release name in repository definitions and package pins. First, the "before" pattern, which breaks the moment the host is on a new release:

# BEFORE: roles/docker/tasks/main.yml (breaks after the upgrade)
- name: Add Docker repo
  ansible.builtin.apt_repository:
    repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu noble stable"  # hardcoded codename
    filename: docker

🧪 Lab — try this in your browser

  • EOL Countdown — Check when your Kubernetes, PostgreSQL, Node.js, Ubuntu… versions lose support. Paste command output or add versions — get status, days left and calendar reminders.

The "after" version derives the codename from facts and gates on the release, so the same role works on both sides of the migration. It also writes a deb822 .sources file with a Signed-By key, which matches Docker's current install method. The deb822_repository module needs python3-debian on the target. Remove any old docker.list file so you do not end up with duplicate sources.

# AFTER: codename comes from facts, not from the file
- name: Add Docker repo for the running release
  ansible.builtin.deb822_repository:
    name: docker
    types: deb
    uris: https://download.docker.com/linux/ubuntu
    suites: "{{ "{{" }} ansible_facts['distribution_release'] }}"
    components: stable
    architectures: "{{ "{{" }} 'amd64' if ansible_facts['architecture'] == 'x86_64' else 'arm64' }}"
    signed_by: https://download.docker.com/linux/ubuntu/gpg
  when: ansible_facts['distribution_version'] is version('24.04', '>=')

- name: Refresh apt cache
  ansible.builtin.apt:
    update_cache: true

Before you upgrade, confirm that each vendor actually publishes a repository for the new codename. Docker Engine 29, for example, is installed from Docker's own repo, so check the Docker install docs for supported releases. If a vendor has not published one yet, that host group waits.

Step-by-step Ubuntu 26.04 upgrade

Run this against a one-host canary group first. The playbook does the following:

  • Refuses to touch anything that is not 24.04.
  • Patches fully and forces the LTS prompt policy.
  • Runs the upgrader with async, so a dropped SSH session does not kill it.
  • Asserts the new release after the final reboot.
# upgrade-2604.yml
- name: Upgrade Ubuntu 24.04 to 26.04
  hosts: upgrade_wave
  become: true
  serial: 1                  # one host at a time
  max_fail_percentage: 0     # stop the whole run on the first failure
  tasks:
    - name: Refuse anything that is not 24.04
      ansible.builtin.assert:
        that: ansible_facts['distribution_version'] == '24.04'

    # Take your snapshot here (cloud API, hypervisor, LVM). Ansible cannot undo this upgrade.

    - name: Fully patch 24.04 first
      ansible.builtin.apt:
        update_cache: true
        upgrade: dist
        autoremove: true

    - name: Check for pending reboot
      ansible.builtin.stat:
        path: /var/run/reboot-required
      register: reboot_flag

    - name: Reboot into the final 24.04 kernel
      ansible.builtin.reboot:
      when: reboot_flag.stat.exists

    - name: Allow LTS upgrades
      ansible.builtin.lineinfile:
        path: /etc/update-manager/release-upgrades
        regexp: '^Prompt='
        line: 'Prompt=lts'

    - name: Confirm an upgrade is offered (fails if none is)
      ansible.builtin.command: do-release-upgrade --check-dist-upgrade-only
      changed_when: false

    - name: Run the release upgrade
      ansible.builtin.command: do-release-upgrade -f DistUpgradeViewNonInteractive
      environment:
        DEBIAN_FRONTEND: noninteractive
      async: 5400            # 90 minutes ceiling
      poll: 30

    - name: Reboot into 26.04
      ansible.builtin.reboot:
        reboot_timeout: 900

    - name: Refresh facts after the upgrade
      ansible.builtin.setup:

    - name: Assert the host is now on 26.04
      ansible.builtin.assert:
        that: ansible_facts['distribution_version'] == '26.04'

Run it with a canary limit. The --diff flag prints file changes, such as the lineinfile edit, as they are applied:

ansible-playbook -i inventory.yml upgrade-2604.yml --limit canary01 --diff
# then widen: --limit 'upgrade_wave:!canary01'

Watch out for non-interactive config-file handling. The non-interactive frontend avoids prompts, which means modified conffiles are resolved automatically. Afterward, review /var/log/dist-upgrade/ and any *.dpkg-new or *.dpkg-old files. Check the Ubuntu Server documentation on upgrades for the exact semantics on your version.

Verify and roll back

Do not rely only on the playbook's green status. Verify the result independently, per host, with an ad-hoc run:

ansible upgrade_wave -b -m ansible.builtin.shell -a \
  '. /etc/os-release && echo "$VERSION_ID" && systemctl --failed --no-legend | wc -l && apt-get check && uname -r'
# expect: 26.04 / 0 failed units / apt-get check silent / a new kernel version

Then run your application-level checks:

  • HTTP health endpoints.
  • Database replication state.
  • Prometheus up for the host's targets.
  • The alert dashboard in Grafana.

A host that boots but has lost its exporter is a quiet failure worth checking for explicitly.

Rollback is a restore, not a downgrade. Ubuntu does not support downgrading a release in place. Your real rollback options are:

  • Restore the pre-upgrade snapshot or image. This is fast, but you lose data written since the snapshot.
  • Rebuild the host from a 24.04 image and re-run your configuration playbooks. This is clean, but it needs your Ansible to be idempotent.
  • Fail traffic over to an untouched replica, for stateful tiers.

That is why serial: 1 and max_fail_percentage: 0 matter. They cap the blast radius at one host. The cost is wall-clock time. Forty hosts, each with two reboots and a long package run, need a long window. For stateless fleets, replacing instances with fresh 26.04 images is often simpler and lower-risk than upgrading in place, especially if image builds are already automated.

Gotchas after the switch

Third-party repositories stay disabled. The upgrader comments out or disables external sources. Re-run your repo roles (the "after" version above). Then confirm with apt-cache policy docker-ce that the candidate comes from the vendor and not from Ubuntu's archive.

Python on the target can change. Your tasks may rely on system Python modules such as python3-apt, python3-debian, or python3-docker. If so, re-run your baseline role first. Leave ansible_python_interpreter on auto discovery unless you have a reason to pin it. Check the ansible-core 2.22 documentation for the supported target-Python versions before you upgrade the control node and the targets together.

Leftover 24.04 package pins. Roles that pin exact versions (postgresql-16=...) will fail or hold packages back. PostgreSQL 18 is the current major, but a major database upgrade is a separate project, so do not combine it with the OS jump. Keep the same major version across the OS upgrade if the package is available, for example from PGDG. Move the database afterward.

Agents and runtimes. Re-check the Java version on Jenkins agents, and rerun your hardening role. Sysctl, SSH, and firewall defaults can differ between releases. Diff your rendered sshd -T output against a pre-upgrade capture.

Finally, record the result in your inventory so later plays can gate on it, for example with an os_release: "26.04" host variable. More runbooks of this kind live on kuryzhev.cloud.

Related

Top comments (0)