ansible-role-os-bootstrap/tasks/apt-hold.yml

32 lines
1.0 KiB
YAML

---
- name: apt-hold | Manage package hold status on Debian/Ubuntu
when:
- ansible_distribution_file_variety == "Debian"
- apt_hold_packages | length > 0
tags: apt_hold
block:
- name: apt-hold | Check which packages are known to dpkg
ansible.builtin.command:
cmd: "dpkg-query -W {{ item }}"
loop: "{{ apt_hold_packages }}"
register: apt_hold_pkg_check
changed_when: false
failed_when: false
- name: apt-hold | Warn about packages not known to dpkg
ansible.builtin.debug:
msg: "WARNING: Package '{{ item.item }}' is not known to dpkg and will be skipped"
loop: "{{ apt_hold_pkg_check.results }}"
when: item.rc != 0
loop_control:
label: "{{ item.item }}"
- name: apt-hold | Apply hold status to known packages
ansible.builtin.dpkg_selections:
name: "{{ item.item }}"
selection: "{{ 'hold' if apt_hold_set else 'install' }}"
loop: "{{ apt_hold_pkg_check.results }}"
when: item.rc == 0
loop_control:
label: "{{ item.item }}"