Biser Milanov | 70bd866 | 2023-12-11 16:28:21 +0200 | [diff] [blame] | 1 | - hosts: all |
| 2 | tasks: |
| 3 | # Unattended-upgrades sometimes do not complete in time and other parts of the setup that use |
| 4 | # `apt` fail with a variation of: |
| 5 | # E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 7929 (unattended-upgr) |
Biser Milanov | f95a3d1 | 2023-12-14 14:18:47 +0200 | [diff] [blame^] | 6 | - name: Disable apt periodic updates |
| 7 | become: yes |
| 8 | ansible.builtin.lineinfile: |
| 9 | path: /etc/apt/apt.conf.d/888disable-periodic |
| 10 | line: "{{ item }}" |
| 11 | state: present |
| 12 | create: yes |
| 13 | loop: |
| 14 | - APT::Periodic::Update-Package-Lists "0"; |
| 15 | - APT::Periodic::Unattended-Upgrade "0"; |
| 16 | |
Biser Milanov | 70bd866 | 2023-12-11 16:28:21 +0200 | [diff] [blame] | 17 | - name: Stop and disable the service unattended-upgrades |
Biser Milanov | 52da397 | 2023-12-12 15:20:57 +0200 | [diff] [blame] | 18 | become: true |
| 19 | ignore_errors: true |
Biser Milanov | 0e2feae | 2023-12-13 16:44:06 +0200 | [diff] [blame] | 20 | ansible.builtin.command: systemctl disable --now unattended-upgrades |
| 21 | |
| 22 | - name: Wait for the lock to get freed |
| 23 | become: true |
Biser Milanov | bc82cda | 2023-12-13 17:20:49 +0200 | [diff] [blame] | 24 | ignore_errors: true |
| 25 | ansible.builtin.shell: fuser /var/lib/dpkg/lock-frontend |
| 26 | register: out |
Biser Milanov | 0e2feae | 2023-12-13 16:44:06 +0200 | [diff] [blame] | 27 | retries: 3600 |
| 28 | delay: 1 |
Biser Milanov | bc82cda | 2023-12-13 17:20:49 +0200 | [diff] [blame] | 29 | until: out.rc == 1 |