aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/roles/rate_mirrors
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-07-31 23:44:54 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-07-31 23:44:54 +0200
commit727ab17a644d52105746e18c301cf733b1181507 (patch)
tree71113c6efae3074899de965aee5489cb76362f8e /src/roles/rate_mirrors
parentdowngrade Ansible (diff)
downloadmaintenance-727ab17a644d52105746e18c301cf733b1181507.tar.gz
maintenance-727ab17a644d52105746e18c301cf733b1181507.zip
move Ansible files to src/
Diffstat (limited to 'src/roles/rate_mirrors')
-rw-r--r--src/roles/rate_mirrors/meta/main.yml3
-rw-r--r--src/roles/rate_mirrors/tasks/main.yml45
2 files changed, 48 insertions, 0 deletions
diff --git a/src/roles/rate_mirrors/meta/main.yml b/src/roles/rate_mirrors/meta/main.yml
new file mode 100644
index 0000000..4516fa1
--- /dev/null
+++ b/src/roles/rate_mirrors/meta/main.yml
@@ -0,0 +1,3 @@
+dependencies:
+ - role: common
+ - {role: etckeeper, when: etc_versioned}
diff --git a/src/roles/rate_mirrors/tasks/main.yml b/src/roles/rate_mirrors/tasks/main.yml
new file mode 100644
index 0000000..9cdab0d
--- /dev/null
+++ b/src/roles/rate_mirrors/tasks/main.yml
@@ -0,0 +1,45 @@
+- 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
+ failed_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-to-file /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
+ failed_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'