deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

Ansible privilege escalation hangs on Ubuntu 26.04; fix only in ansible-core 2.20+

Ubuntu 26.04's Rust-based sudo prints a password prompt Ansible does not recognise, hanging playbooks for 12 seconds. A dev.to reproduction finds the fix only in released ansible-core 2.20 patches, not the older branches.

Ansible privilege escalation hangs on Ubuntu 26.04; fix only in ansible-core 2.20+

A 12-second hang on the first task

Playbooks that escalate privileges with a password now stall outright against freshly installed Ubuntu 26.04 machines, a problem first reported by Jeff Geerling and reproduced in detail in a dev.to write-up. The failure arrives on the very first task of a play — the fact-gathering step, before any real command runs — and it always ends the same way: roughly twelve to thirteen seconds of silence, then a fatal error saying Ansible timed out waiting for the privilege escalation prompt. The dev.to author ran a one-task playbook three times with ansible-core 2.17.6 and saw consistent failures at about 12.8 seconds; the correct password sat in the inventory the whole time, but Ansible never got far enough to send it.

The cause sits on the Ubuntu side: version 26.04 makes a Rust rewrite of sudo called sudo-rs its new default implementation.

The prompt mismatch

Ansible deliberately dictates the exact prompt text sudo should print, so it knows precisely which string to wait for on the wire. Capturing the raw output of both implementations answering the same request exposes the difference: traditional sudo echoes the requested prompt verbatim, while sudo-rs embeds that text inside a fixed template of its own and appends its own capitalised Password: prompt. Because Ansible matches on the exact string it supplied, the extra wrapping is enough for the match to fail, and the connection idles until the 12-second timeout expires.

The fix, examined by the dev.to author in Ansible's sudo become plugin, adds a second regular expression that recognises the sudo-rs output format. The comment accompanying that change in Ansible's source describes sudo-rs as not backwards compatible, suggesting the project treats this as a behavioural change in sudo rather than a cosmetic wording difference.

The backports have not shipped

The original report said the fix landed in ansible-core 2.22.0 and was backported to the 2.16, 2.18, 2.19 and 2.20 branches, with 2.21 listed as a possibility. The dev.to reproduction complicates that picture. Testing the newest released patch of each branch from PyPI, versions 2.16.20, 2.17.6, 2.18.20 and 2.19.15 all still fail with the 12-second timeout, while 2.20.11, 2.21.6 and 2.22.0 complete in roughly 2.1 seconds. As of the write-up, no released patch of the older branches carries the fix, so upgrading within those branches delivers nothing.

That is awkward because the older branches exist to support older Python versions. A control node running Python 3.11, the version Debian 12 ships, illustrates the trap: installing the plain ansible meta-package into a clean 3.11 environment resolves to ansible-core 2.19.15, exactly one of the versions that still fails. On such a node, upgrading the ansible package does not help. The only working path today is ansible-core 2.20 or newer, which requires Python 3.12 on the control node. Ubuntu 24.04's system Python already satisfies that; a Debian 12 node does not.

Passwordless sudo is unaffected

The bug cannot reach hosts where sudo needs no password. Cloud images that grant their default user passwordless sudo through cloud-init never produce a prompt for Ansible to miss, and the dev.to author confirmed that unpatched 2.17.6 completes in about two seconds against a NOPASSWD user. The failure only bites when a become password is actually configured — typically hosts where sudo was deliberately locked behind one.

The workaround, and what it costs at scale

The suggested workaround — keeping the traditional sudo binary installed alongside sudo-rs and pointing Ansible at it with ansible_become_exe=sudo.ws — holds up in testing, completing at roughly the speed of the fixed versions. The catch is that the classic sudo package must genuinely be present. Ubuntu's packaging retains both binaries and uses update-alternatives to decide which one answers to /usr/bin/sudo, but minimal images, including the official Docker image the author started from, do not include the older package by default.

Scale changes the arithmetic. One stuck host costs about 13 seconds, and because per-host timers run in parallel, a batch that fits within the default fork count pays that price once: three affected hosts with 5 forks still failed in around 13 seconds. Forced serial execution with --forks 1 stretched the same three hosts to roughly 37 seconds, nearly triple, because each timeout blocks the next connection. For serial rolling deploys, the widely quoted 12-second figure is per batch, not per run.

Why it matters

This is a breaking change sitting where two defaults meet: Ubuntu 26.04's adoption of sudo-rs and Ansible's password-based privilege escalation. It surfaces only on fresh systems with password-gated sudo, and the symptom — a generic escalation timeout — offers no hint that a Rust rewrite of sudo is responsible, which makes diagnosis slow. Teams pinned to older ansible-core branches, often because their control nodes run older Python, cannot fix this by upgrading within the branch, and the backport status reported at the time does not match what has actually shipped. Anyone aiming playbooks at new Ubuntu 26.04 hosts should move the control node to ansible-core 2.20 or newer, install classic sudo and set ansible_become_exe on affected hosts, or confirm their hosts rely on passwordless sudo.

  • #ansible
  • #ubuntu
  • #sudo-rs
  • #devops
  • #linux