summaryrefslogtreecommitdiff
path: root/roles/upgrade/tasks/main.yml
blob: df7360de3bee9206c916cf6f131de9260fe6e701 (plain) (blame)
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
---
- name: Update packages list
  apt:
    update_cache: yes

- name: List packages to upgrade (1/2)
  command: aptitude -q -F%p --disable-columns search '~U !~ahold'
  check_mode: no
  register: updates
  changed_when: False
  failed_when: updates.rc != 0 and updates.rc != 1

- name: List packages to upgrade (2/2)
  debug:
    msg: "{{ updates.stdout_lines | count }} packages to upgrade ({{ updates.stdout_lines | join(', ') }})"
  when: updates.stdout_lines

- name: Upgrade packages
  apt:
    upgrade: safe

- name: List services to restart (1/2)
  shell: checkrestart | grep ^service | awk '{print $2}'
  check_mode: no
  register: services
  changed_when: False

- name: List services to restart (2/2)
  debug:
    msg: "{{ services.stdout_lines | count }} services to restart ({{ services.stdout_lines | join (', ') }})"
  when: services.stdout_lines

- name: clean apt-cache and remove stale packages
  apt:
    autoclean: yes
    autoremove: yes