summaryrefslogtreecommitdiffstatshomepage
path: root/roles/pacman/tasks/main.yml
blob: 7683935d7d2596346912121d20be3df70773bd3a (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
37
38
39
40
41
42
43
44
45
46
47
- name: Upgrade packages
  become: true
  community.general.pacman:
    update_cache: true
    upgrade: true
  register: pacman_result
  # According to
  #     https://docs.ansible.com/projects/ansible/latest/collections/community/general/pacman_module.html
  # this module now reports 'changed' even if only the cache was updated, with
  # no upgrades; this is the workaround.
  changed_when: pacman_result.packages is defined and (pacman_result.packages | length > 0)

- name: Post-upgrade
  when: pacman_result is changed
  block:
    - name: Show upgraded packages
      ansible.builtin.debug:
        var: pacman_result.packages | sort

    - name: Reboot
      become: true
      ansible.builtin.reboot:
        # 3 minutes is plenty.
        reboot_timeout: 180

- name: Get list of unneeded dependencies
  ansible.builtin.command: pacman -Qqdt
  register: pacman_result
  changed_when: false
  failed_when: |
    pacman_result.rc != 0
    and not (pacman_result.rc == 1 and (pacman_result.stdout_lines | length == 0))

- name: Remove unneeded dependencies
  become: true
  community.general.pacman:
    name: '{{ pacman_result.stdout_lines }}'
    state: absent
    extra_args: --recursive
    remove_nosave: true
  when: pacman_result.stdout_lines | length > 0
  register: pacman_result

- name: Show removed packages
  ansible.builtin.debug:
    var: pacman_result.packages | sort
  when: pacman_result.packages is defined