ansible-infra/ansible_collections/debops/debops/roles/apt_mark/tasks/main.yml
Stefan Bethke 2aed20393f
Some checks failed
/ Ansible Lint (push) Failing after 5m45s
/ Ansible Lint (pull_request) Failing after 4m59s
Vendor Galaxy Roles and Collections
2026-02-06 22:07:16 +01:00

96 lines
4.4 KiB
YAML

---
# Copyright (C) 2018 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2018 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only
- name: Import custom Ansible plugins
ansible.builtin.import_role:
name: 'ansible_plugins'
- name: Configure APT autoremove options
ansible.builtin.template:
src: 'etc/apt/apt.conf.d/25autoremove-recommends.conf.j2'
dest: '/etc/apt/apt.conf.d/25autoremove-recommends.conf'
owner: 'root'
group: 'root'
mode: '0644'
when: apt_mark__enabled | bool
- name: Check state of the APT packages
ansible.builtin.script: 'script/apt-mark-status{{ "2" if (ansible_python_version is version_compare("3.5", "<")) else "3" }}'
register: apt_mark__register_state
changed_when: False
check_mode: False
when: apt_mark__enabled | bool
- name: Set facts about APT package state
ansible.builtin.set_fact:
apt_mark__fact_auto: '{{ (apt_mark__register_state.stdout | from_json)["auto"] }}'
apt_mark__fact_hold: '{{ (apt_mark__register_state.stdout | from_json)["hold"] }}'
apt_mark__fact_installed: '{{ (apt_mark__register_state.stdout | from_json)["installed"] }}'
apt_mark__fact_manual: '{{ (apt_mark__register_state.stdout | from_json)["manual"] }}'
when: apt_mark__enabled | bool
- name: Set package state as installed automatically
ansible.builtin.command: apt-mark auto {{ ((item.packages | d([item.name])) | intersect(apt_mark__fact_installed)) | join(' ') }}
with_items: '{{ apt_mark__combined_packages | debops.debops.parse_kv_items }}'
register: apt_mark__register_auto
changed_when: apt_mark__register_auto.changed | bool
when: (apt_mark__enabled | bool and
(item.packages | d([item.name]) | intersect(apt_mark__fact_installed))
| symmetric_difference(apt_mark__fact_manual) and
(item.packages | d([item.name]) | intersect(apt_mark__fact_installed))
| difference(apt_mark__fact_auto) and
item.state | d('manual') in ['auto', 'auto-hold', 'auto-unhold'])
- name: Set package state as installed manually
ansible.builtin.command: apt-mark manual {{ ((item.packages | d([item.name]))
| intersect(apt_mark__fact_installed)) | join(' ') }}
with_items: '{{ apt_mark__combined_packages | debops.debops.parse_kv_items }}'
register: apt_mark__register_manual
changed_when: apt_mark__register_manual.changed | bool
when: (apt_mark__enabled | bool and
(item.packages | d([item.name]) | intersect(apt_mark__fact_installed))
| symmetric_difference(apt_mark__fact_auto) and
(item.packages | d([item.name]) | intersect(apt_mark__fact_installed))
| difference(apt_mark__fact_manual) and
item.state | d('manual') in ['manual', 'manual-hold', 'manual-unhold'])
- name: Hold current package state
ansible.builtin.command: apt-mark hold {{ ((item.packages | d([item.name]))
| intersect(apt_mark__fact_installed)) | join(' ') }}
with_items: '{{ apt_mark__combined_packages | debops.debops.parse_kv_items }}'
register: apt_mark__register_hold
changed_when: apt_mark__register_hold.changed | bool
when: (apt_mark__enabled | bool and
(item.packages | d([item.name]) | intersect(apt_mark__fact_installed))
| difference(apt_mark__fact_hold) and
item.state | d('manual') in ['hold', 'auto-hold', 'manual-hold'])
- name: Unhold current package state
ansible.builtin.command: apt-mark unhold {{ ((item.packages | d([item.name]))
| intersect(apt_mark__fact_installed)) | join(' ') }}
with_items: '{{ apt_mark__combined_packages | debops.debops.parse_kv_items }}'
register: apt_mark__register_unhold
changed_when: apt_mark__register_unhold.changed | bool
when: (apt_mark__enabled | bool and
(item.packages | d([item.name]) | intersect(apt_mark__fact_installed))
| intersect(apt_mark__fact_hold) and
item.state | d('manual') in ['unhold', 'auto-unhold', 'manual-unhold'])
- name: Make sure that Ansible local facts directory exists
ansible.builtin.file:
path: '/etc/ansible/facts.d'
state: 'directory'
owner: 'root'
group: 'root'
mode: '0755'
- name: Save apt-mark local facts
ansible.builtin.template:
src: 'etc/ansible/facts.d/apt_mark.fact.j2'
dest: '/etc/ansible/facts.d/apt_mark.fact'
owner: 'root'
group: 'root'
mode: '0755'
tags: [ 'meta::facts' ]