From e2d23269a1847107bda7918eeb24cf66b376c9ba Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 4 Sep 2023 21:31:18 +0200 Subject: import roles etckeeper, pacman, rate_mirrors --- roles/rate_mirrors/meta/main.yml | 2 ++ roles/rate_mirrors/tasks/main.yml | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 roles/rate_mirrors/meta/main.yml create mode 100644 roles/rate_mirrors/tasks/main.yml (limited to 'roles/rate_mirrors') diff --git a/roles/rate_mirrors/meta/main.yml b/roles/rate_mirrors/meta/main.yml new file mode 100644 index 0000000..cc61eb8 --- /dev/null +++ b/roles/rate_mirrors/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - role: etckeeper diff --git a/roles/rate_mirrors/tasks/main.yml b/roles/rate_mirrors/tasks/main.yml new file mode 100644 index 0000000..6fb57e4 --- /dev/null +++ b/roles/rate_mirrors/tasks/main.yml @@ -0,0 +1,43 @@ +- name: As root user + become: true + block: + - name: Fail if there're uncommitted changes in /etc + when: etc_versioned + block: + - name: Check for changes in /etc + ansible.builtin.command: git status --porcelain=v1 + args: + chdir: /etc + register: git_status + changed_when: false + + - ansible.builtin.fail: + msg: There are uncommitted changes in /etc + when: git_status.stdout + + - name: Rate pacman mirrors + 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 + block: + - name: Check for changes in /etc + ansible.builtin.command: git status --porcelain=v1 + args: + chdir: /etc + register: git_status + changed_when: false + + - name: Fail if there're other uncommitted changes + ansible.builtin.fail: + msg: How did this happen? + when: git_status.stdout != ' M pacman.d/mirrorlist' + + - name: Commit changes in /etc/pacman.d/mirrorlist + ansible.builtin.command: | + etckeeper commit 'rate-mirrors' -- cgit v1.2.3