Ansible started our security updates on forty gateways in the background and six of them failed where nobody looked
Our forty integration gateways are Debian servers, and once a month a playbook applies security updates to them: apt upgrade, then a reboot where one is needed.
Run in batches, it took about ninety minutes, and in the summer a colleague made it faster. He gave the upgrade task async: 3600 and poll: 0, so Ansible would start the upgrade on every gateway and move on instead of waiting. The run dropped to four minutes, the recap showed no failures, and everyone was pleased.
In November our quarterly vulnerability scan listed six gateways as three months behind on OpenSSL and OpenSSH. The patch playbook had run on them every month, and every month it had been green.
Fire and forget
poll: 0 is the setting Ansible calls fire and forget. It starts the task on the host as a background job, records a job id, and goes straight on to the next task without ever asking how the job ended. Whatever happens after that is not part of the play.
On those six gateways the background apt run could not get the dpkg lock, because unattended-upgrades was holding it at the same moment, and it failed. The reason was written down every time, in a status file under /root/.ansible_async on each gateway, where Ansible keeps the result of every async job. Nobody had ever read them.
Ansible's own documentation warns against poll: 0 for anything that needs an exclusive lock, which a package manager does.
What actually made it fast
The speed had never come from poll: 0 anyway. It came from running forty hosts at once instead of in batches, which Ansible does with forks.
The upgrade task still runs with async, because a long upgrade can outlive an SSH session, but it is followed by an async_status task on the registered job id, with until result.finished, retries and a delay. That task waits for each host's job to end and fails the host if the job failed.
A final task counts the packages apt still lists as upgradable and fails the gateway if that is more than zero, so the play now checks the result it was written to produce. unattended-upgrades is stopped for the duration of the run.
The six gateways were patched that afternoon. The play had been honest. It reported that it started the upgrades, and that was all it ever knew. - Sergey Shinder
Comments
No comments yet. Start the discussion.