Stop Ansible from hanging on your CI runners when a background task leaks

DevOps Tooling On Linux (CI/CD Runners, Ansible)

Stop Ansible from hanging on your CI runners when a background task leaks

Technical Briefing | 9/20/2026

We have all seen that CI runner that stays stuck for an hour, consuming zero CPU, while the build job just sits there spinning. It usually happens when Ansible triggers a background service or an interactive shell process that decides not to exit cleanly when the SSH connection drops. Your pipeline expects a clean exit code, but instead, you get a zombie process holding onto a pipe, and your runner effectively dies until the next manual cleanup.

Why the standard async module won’t save you here

You might reach for the Ansible async module thinking it handles the connection decoupling for you. But if you are starting a process that inherits your shell’s file descriptors, it might keep those descriptors open long after the task completes. This is a classic leak that drives sysadmins crazy because the process looks finished on the surface, but the shell is waiting for those pipes to close before it returns control to your automation runner.

ansible all -a 'nohup ./your-script.sh > /dev/null 2>&1 < /dev/null & disown'

  • Redirect all standard streams to dev null to ensure no hanging file descriptors
  • Use disown to remove the process from the shell job table immediately
  • Force the command into a separate process group so it survives the SSH disconnect
  • Avoid using shell modules for long running services if systemd is an option

Stop treating your CI runner like an interactive login shell

When you execute commands through Ansible, the remote shell environment can be temperamental about child processes. If you find your CI jobs getting stuck, check if you have children that ignore SIGHUP. Just because the automation tool finishes doesn’t mean your shell has actually logged out, and that lingering session is just a time bomb waiting to eat your runner capacity. If you really need to run something in the background, systemd is your friend; leave the ad-hoc scripts for things that actually exit when they say they will.

Linux Admin Automation  |  © www.ngelinux.com  |  9/20/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted