David K. Bainbridge | ca68f06 | 2016-10-27 11:04:33 -0700 | [diff] [blame] | 1 | --- |
| 2 | - name: Ensure Local Repository Settings |
| 3 | become: yes |
| 4 | template: |
| 5 | backup: yes |
| 6 | dest: /etc/apt/sources.list |
David K. Bainbridge | dbf9f69 | 2016-11-04 11:51:32 +0100 | [diff] [blame] | 7 | src: sources.list.j2 |
David K. Bainbridge | ca68f06 | 2016-10-27 11:04:33 -0700 | [diff] [blame] | 8 | group: root |
| 9 | owner: root |
| 10 | mode: 0644 |
| 11 | when: ubuntu_apt_repo is defined |
| 12 | |
| 13 | - name: Capture Existing Respositories |
| 14 | command: find /etc/apt/sources.list.d \! -type d -name '*.list' |
| 15 | changed_when: false |
| 16 | register: existing_repo_lists |
| 17 | when: ubuntu_apt_repo is defined |
| 18 | |
| 19 | - name: Capture Timestamp |
| 20 | set_fact: |
| 21 | timestamp: "{{ lookup('pipe', 'date +%Y-%m-%d@%H:%M:%S') }}" |
| 22 | changed_when: false |
| 23 | when: ubuntu_apt_repo is defined |
| 24 | |
David K. Bainbridge | dbf9f69 | 2016-11-04 11:51:32 +0100 | [diff] [blame] | 25 | - name: Backup Existing Respositories |
| 26 | become: yes |
| 27 | copy: |
| 28 | remote_src: True |
| 29 | src: "{{ item }}" |
| 30 | dest: "{{ item }}.{{ timestamp }}~" |
| 31 | with_items: "{{ existing_repo_lists['stdout_lines'] | default([]) }}" |
| 32 | when: ubuntu_apt_repo is defined |
David K. Bainbridge | ca68f06 | 2016-10-27 11:04:33 -0700 | [diff] [blame] | 33 | |
David K. Bainbridge | dbf9f69 | 2016-11-04 11:51:32 +0100 | [diff] [blame] | 34 | - name: Remove Existing Repositories |
| 35 | become: yes |
| 36 | file: |
| 37 | state: absent |
| 38 | path: "{{ item }}" |
| 39 | with_items: "{{ existing_repo_lists['stdout_lines'] | default([]) }}" |
| 40 | when: ubuntu_apt_repo is defined |
David K. Bainbridge | ca68f06 | 2016-10-27 11:04:33 -0700 | [diff] [blame] | 41 | |
David K. Bainbridge | dbf9f69 | 2016-11-04 11:51:32 +0100 | [diff] [blame] | 42 | - name: Ensure Update Repository List |
| 43 | become: yes |
| 44 | apt: |
| 45 | update_cache: yes |
| 46 | when: ubuntu_apt_repo is defined |