-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
packages.yml
88 lines (84 loc) · 2.28 KB
/
packages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
- name: Disable APT recommends
ansible.builtin.blockinfile:
path: /etc/apt/apt.conf.d/02norecommends
mode: 0644
create: true
block: |
APT::Install-Recommends "false";
APT::Install-Suggests "false";
APT::Get::Install-Recommends "false";
APT::Get::Install-Suggests "false";
- name: Upgrade all system packages
ansible.builtin.apt:
upgrade: full
update_cache: true
cache_valid_time: 3600
autoclean: true
autoremove: true
register: apt_upgrade
retries: 5
until: apt_upgrade is success
- name: Install common packages
ansible.builtin.apt:
name: "{{ apt_install_packages }}"
install_recommends: false
update_cache: true
cache_valid_time: 3600
autoclean: true
autoremove: true
register: apt_install_common
retries: 5
until: apt_install_common is success
when:
- apt_install_packages is defined
- apt_install_packages is iterable
- apt_install_packages | length > 0
- name: Gather installed packages
ansible.builtin.package_facts:
manager: auto
- name: Remove packages
block:
- name: Check if snap is installed
ansible.builtin.debug:
msg: "snapd is installed"
register: snapd_check
when:
- "'snapd' in apt_remove_packages"
- "'snapd' in ansible_facts.packages"
- name: Remove snap packages
ansible.builtin.command: snap remove {{ item }}
loop:
- lxd
- core18
- core20
- snapd
when:
- "'snapd' in apt_remove_packages"
- "'snapd' in ansible_facts.packages"
- snapd_check.failed is defined
- name: Remove packages
ansible.builtin.apt:
name: "{{ apt_remove_packages }}"
state: absent
autoremove: true
- name: Remove files
ansible.builtin.file:
state: absent
path: "{{ item }}"
loop:
- "/home/{{ ansible_user }}/.snap"
- "/snap"
- "/var/snap"
- "/var/lib/snapd"
- "/var/cache/snapd"
- "/usr/lib/snapd"
- "/etc/cloud"
- "/var/lib/cloud"
when:
- "'snapd' in apt_remove_packages"
- "'cloud-init' in apt_remove_packages"
when:
- apt_remove_packages is defined
- apt_remove_packages is iterable
- apt_remove_packages | length > 0