aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/rate_mirrors/tasks/main.yml
blob: 9d40fa237ec19f39f21deea3fd13682546482da3 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
- name: Check if /etc is versioned
  become: true
  ansible.builtin.file:
    path: /etc/.git/config
    state: file
  register: etc_versioned

- name: Fail if there're uncommitted changes in /etc
  when: etc_versioned
  become: true
  block:
    - name: Check for changes in /etc
      ansible.builtin.command: # noqa: command-instead-of-module
        cmd: git status --porcelain=v1
        chdir: /etc
      register: git_status
      changed_when: false

    - name: Fail
      ansible.builtin.fail:
        msg: |
          There are uncommitted changes in /etc:
          {{ git_status.stdout }}
      when: git_status.stdout

- name: Rate pacman mirrors
  become: true
  ansible.builtin.shell: |
    . /etc/os-release && rate-mirrors \
        --allow-root \
        --disable-comments \
        --save /etc/pacman.d/mirrorlist \
        "$ID"

- name: Commit pacman.d/mirrorlist
  when: etc_versioned
  become: true
  block:
    - name: Check for changes in /etc
      ansible.builtin.shell: |
        set -o pipefail && \
        git status --porcelain=v1 \
            | cut -c 4- \
            | grep -G -v '^pacman.d/mirrorlist'
      args:
        chdir: /etc
      register: git_status
      changed_when: false
      failed_when: git_status.rc not in [0, 1]

    - name: Fail if there're other uncommitted changes
      ansible.builtin.fail:
        msg: |
          How did this happen? Other files have been modified:
          {{ git_status.stdout }}
      when: git_status.rc == 0

    - name: etckeeper commit
      ansible.builtin.command: |
        etckeeper commit 'rate-mirrors'