Ansible hangs, then times out waiting for the sudo prompt
Timeout (12s) waiting for privilege escalation promptShort answer
Ansible ran sudo on the target and never saw the answer it expected. Most often sudo wanted a password Ansible did not have, or the become method or sudo path is wrong for that host. A slow host can also exceed the connection timeout. Rerun with -K and -vvv to see which.
Fix it fast
1Find out which cause you have
Rerun the failing play with verbose output and ask for the become password. If it now works, the missing password was the cause.
ansible-playbook site.yml -i inventory.ini -K -vvv2Match what you see, then jump to its fix
- 1
The play hangs at the first become task and works with -Ksudo needs a password and Ansible was not given oneFix - 2
The host uses su, doas or a sudo outside the default path, so the expected prompt never appearsThe become method or sudo path does not match the hostFix - 3
Fails only on busy or distant hosts, and passes when retriedThe connection timeout is too short for a slow hostFix
- 1
What does the error look like?
Timeout (12s) waiting for privilege escalation prompta playbook using become seems to hang
Cause 1 of 3
sudo needs a password and Ansible was not given one
1Check
Ansible's documentation says a playbook that appears to hang is most likely stuck at the privilege escalation prompt. Check whether your user can run sudo without a password.
ssh -i key.pem ubuntu@host 'sudo -n true && echo passwordless'2Fix
Give Ansible the password at run time with -K, or store it encrypted with Ansible Vault and reference it as ansible_become_password. Never keep it in plain text.
ansible-playbook site.yml -K
# or in a vault-encrypted vars file
ansible_become_password: "{{ vault_sudo_password }}"3Verify
The play passes its first become task.
ansible all -i inventory.ini -b -m ping -KConfirmed by docs.ansible.com
Cause 2 of 3
The become method or sudo path does not match the host
1Check
Ansible uses sudo by default. Other methods exist, such as su and doas, and the sudo executable can be set separately.
ssh -i key.pem ubuntu@host 'command -v sudo doas su'2Fix
Name the method the host really uses, or the full path to sudo, for the group in the inventory.
[web:vars]
ansible_become=true
ansible_become_method=sudo
ansible_become_exe=/usr/bin/sudo3Verify
Run a privileged ping against the group.
ansible web -i inventory.ini -b -m pingConfirmed by docs.ansible.com
Cause 3 of 3
The connection timeout is too short for a slow host
1Check
The default timeout for connection plugins is 10 seconds, set by the timeout setting in ansible.cfg or ANSIBLE_TIMEOUT. Raising it tells you whether time is the limit.
ansible-config dump | grep -i DEFAULT_TIMEOUT2Fix
Raise it for this run, or for the project in ansible.cfg.
ANSIBLE_TIMEOUT=30 ansible-playbook site.yml -K
# ansible.cfg
[defaults]
timeout = 303Verify
Rerun the play on the slow host.
ansible-playbook site.yml -i inventory.ini -KConfirmed by docs.ansible.com
How do I stop it coming back?
- Use a dedicated deploy user with passwordless sudo only for the commands the play needs.
- Keep ansible_become_password in Ansible Vault, never in the inventory.
- Run a small `-b -m ping` check against new hosts before the real playbook.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fixServers
Apache refuses to start: DefaultRuntimeDir must be a valid directory
DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot
DefaultRuntimeDir is where Apache creates run-time files such as shared memory and locks.
2 causes, each with a fix