From d83200c5305fcf7d6c26eb4f541e17ddd0770b96 Mon Sep 17 00:00:00 2001 From: "Jon \"The Nice Guy\" Spriggs" Date: Fri, 8 Jan 2021 15:44:42 +0000 Subject: [PATCH] Documentation change to the apt module to reference lock files (#73079) This change references the suggested workaround in #25414. Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com> --- lib/ansible/modules/apt.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py index 9c541d8f0e6..cd36b622310 100644 --- a/lib/ansible/modules/apt.py +++ b/lib/ansible/modules/apt.py @@ -268,6 +268,17 @@ EXAMPLES = ''' apt: autoremove: yes +# Sometimes apt tasks fail because apt is locked by an autoupdate or by a race condition on a thread. +# To check for a lock file before executing, and keep trying until the lock file is released: +- name: Install packages only when the apt process is not locked + apt: + name: foo + state: present + register: apt_action + retries: 100 + until: apt_action is success or ('Failed to lock apt for exclusive operation' not in apt_action.msg and '/var/lib/dpkg/lock' not in apt_action.msg) + + ''' RETURN = '''