aboutsummaryrefslogblamecommitdiffstatshomepage
path: root/roles/rate_mirrors/tasks/main.yml
blob: 4d76ff3e8f39d25c47ac26f4b017072ce505df60 (plain) (tree)
1
2
3
4
5
6
7
8

                    
        

                                                        

                                         
                                                            





                              
                               



                                                      
                              




                                             
 

                                      

                                         
                                                            





                              

                                                          



                                                             
                                    
                                           
- 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=/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'