It seems that getting failures due to /var/lib/dpkg/lock is something not very rare. Based on observations these are caused most of the time 9/10 due to state lock file or while a cron job was running.
This means that a retry mechanism combined with a removal of stale file could be the solution.
How can I do this in ansible?
wait_for
module to wait for the lock file to disappear and then run your apt.wait_for
that way.