From 9f1864783f3a4465944854e6cfa2b6177725f864 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 11 Sep 2023 14:21:19 +0200 Subject: rate_mirrors: drop dependency on etckeeper role, refactoring --- roles/rate_mirrors/meta/main.yml | 2 - roles/rate_mirrors/tasks/main.yml | 88 +++++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 38 deletions(-) delete mode 100644 roles/rate_mirrors/meta/main.yml diff --git a/roles/rate_mirrors/meta/main.yml b/roles/rate_mirrors/meta/main.yml deleted file mode 100644 index cc61eb8..0000000 --- a/roles/rate_mirrors/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - role: etckeeper diff --git a/roles/rate_mirrors/tasks/main.yml b/roles/rate_mirrors/tasks/main.yml index 6fb57e4..d000b13 100644 --- a/roles/rate_mirrors/tasks/main.yml +++ b/roles/rate_mirrors/tasks/main.yml @@ -1,43 +1,59 @@ -- name: As root user +- 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: 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 + - 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 + - ansible.builtin.fail: + msg: | + There are uncommitted changes in /etc: + {{ git_status.stdout }} + 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: 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 - block: - - name: Check for changes in /etc - ansible.builtin.command: git status --porcelain=v1 - args: - chdir: /etc - register: git_status - changed_when: false +- 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? - when: git_status.stdout != ' M pacman.d/mirrorlist' + - 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: Commit changes in /etc/pacman.d/mirrorlist - ansible.builtin.command: | - etckeeper commit 'rate-mirrors' + - name: etckeeper commit + ansible.builtin.command: | + etckeeper commit 'rate-mirrors' -- cgit v1.2.3