-
Notifications
You must be signed in to change notification settings - Fork 2
/
apt-maintenance.yml
49 lines (42 loc) · 1.53 KB
/
apt-maintenance.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
# https://docs.ansible.com/ansible/latest/modules/apt_module.html
# https://docs.ansible.com/ansible/latest/modules/debconf_module.html
- hosts: debian-8 , debian-9 , ubuntu-12 , ubuntu-14 , ubuntu-16 , ubuntu-18
become: yes
tasks:
- name: Check for updates
#command: bash -c "aptitude update | egrep -v '://'"
apt:
update_cache: yes
cache_valid_time: 3600
- name: Install 'unattended-upgrades'
apt:
name: "{{ packages }}"
state: present
vars:
packages:
- unattended-upgrades
- name: Configure 'unattended-upgrades'
debconf:
name: unattended-upgrades
question: unattended-upgrades/enable_auto_updates
vtype: boolean
value: 'true'
- name: List available updates
command: bash -c "apt list --upgradable || aptitude --simulate --show-why --download-only --assume-yes safe-upgrade || apt-get --simulate --no-download --assume-yes"
register: output
- debug: var=output.stdout_lines
- name: Remove useless packages from the cache
#command: bash -c "echo autoclean clean purge | xargs -r -t -n 1 apt-get"
apt:
autoclean: yes
- name: Remove dependencies that are no longer required
#command: bash -c "apt-get --simulate --assume-yes autoremove"
apt:
autoremove: yes
register: output
- debug: var=output.stdout_lines
- name: Update all packages to the latest version
apt:
upgrade: safe
register: output
- debug: var=output.stdout_lines