diff --git a/ansible/playbooks/fully-patch-system.yaml b/ansible/playbooks/fully-patch-system.yaml index 24c4b717..4bbd5eb8 100644 --- a/ansible/playbooks/fully-patch-system.yaml +++ b/ansible/playbooks/fully-patch-system.yaml @@ -7,6 +7,46 @@ use_reboottimeout: 600 tasks: + - name: Check if Zypper lock file exists + stat: + path: /var/run/zypp.pid + register: lockfile_check + become: yes + + - name: Get PID from Zypper lock file + slurp: + src: /var/run/zypp.pid + register: pid_content + become: yes + when: lockfile_check.stat.exists and lockfile_check.stat.size > 0 + + - name: Set PID variable + set_fact: + zypper_pid: "{{ (pid_content['content'] | b64decode).strip() }}" + when: lockfile_check.stat.exists and lockfile_check.stat.size > 0 + + - name: Kill process with the PID + command: kill -9 {{ zypper_pid }} + become: yes + ignore_errors: yes + when: zypper_pid is defined + + - name: Wait to confirm the process is dead + command: ps -p {{ zypper_pid }} -o comm= + register: process_check + retries: 5 + delay: 2 + until: process_check.rc != 0 + failed_when: false + when: zypper_pid is defined + + - name: Remove stale Zypper lock file + file: + path: /var/run/zypp.pid + state: absent + become: yes + when: lockfile_check.stat.exists and (lockfile_check.stat.size == 0 or zypper_pid is defined) + # Fully patch system - name: Apply all available patches community.general.zypper: