Site icon New Generation Enterprise Linux

Stop your Ansible persistent connections from leaking process memory on CI runners

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

Stop your Ansible persistent connections from leaking process memory on CI runners

Technical Briefing | 8/3/2026

You probably think your CI runners are ephemeral, so memory leaks don’t matter much. That is until your Gitlab runner nodes start hitting OOM kills three days into a deployment cycle because Ansible keeps holding onto SSH control sockets. I have seen this drag down a perfectly stable fleet of build agents.

Why the connection pool never actually dies

By default, Ansible keeps an SSH control socket open for the duration of the playbook execution to avoid the overhead of re-authenticating every single task. That makes sense for long-running playbooks. But on a runner that handles hundreds of jobs a day, these processes often outlive their parent shells or fail to reap properly when a task throws a hard exit. You end up with a pile of idle ssh-agent processes and master control sockets clinging to old file descriptors.

find ~/.ansible/cp -type s -mmin +60 -delete
  • ControlPath defines where those sockets live, so point it to /tmp if you want the system to clean it up via tmpwatch
  • Setting pipelining to true reduces the number of shell operations but doesn’t solve the socket cleanup problem
  • The ControlPersist value in your ssh config should be set to something low like 30s for automated tasks

If you are running Ansible in a containerized environment, force a cleanup in your entrypoint or as a post-job cleanup hook. Don’t rely on the ssh daemon to clean up after your automation. Just prune the directory regularly and watch your memory utilization flatten out.

Linux Admin Automation  |  © www.ngelinux.com  |  8/3/2026
0 0 votes
Article Rating
Exit mobile version