From cc4561d9c5a67c1d207ae1be46dbfece14a2deb7 Mon Sep 17 00:00:00 2001 From: administrator Date: Mon, 24 Aug 2026 10:23:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20playbooks/update=5Frepositories.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playbooks/update_repositories.yml | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 playbooks/update_repositories.yml diff --git a/playbooks/update_repositories.yml b/playbooks/update_repositories.yml new file mode 100644 index 0000000..0d5b529 --- /dev/null +++ b/playbooks/update_repositories.yml @@ -0,0 +1,72 @@ +--- +- name: Automatically set up-to-date APT repositories (Debian/Raspberry Pi) + hosts: all + become: yes + gather_facts: yes + + vars: + distro_codename: "{{ ansible_distribution_release }}" + + # Содержимое для /etc/apt/sources.list (CDN Debian) + sources_list_content: | + deb https://deb.debian.org/debian {{ distro_codename }} main contrib non-free non-free-firmware + deb https://security.debian.org/debian-security {{ distro_codename }}-security main contrib non-free non-free-firmware + deb https://deb.debian.org/debian {{ distro_codename }}-updates main contrib non-free non-free-firmware + + # Содержимое для raspi.list (только если это Raspberry Pi) + raspi_list_content: | + deb http://archive.raspberrypi.com/debian/ {{ distro_codename }} main + + tasks: + # 1. Удаляем все старые файлы в /etc/apt/sources.list.d/, + # чтобы исключить конфликты (включая .sources и .list) + - name: Backup current sources.list.d directory + copy: + src: /etc/apt/sources.list.d + dest: "/etc/apt/sources.list.d.backup_{{ ansible_date_time.epoch }}" + remote_src: yes + ignore_errors: yes + + - name: Remove all files in /etc/apt/sources.list.d/ + file: + path: "{{ item }}" + state: absent + loop: + - /etc/apt/sources.list.d/debian.sources + - /etc/apt/sources.list.d/raspi.sources + - /etc/apt/sources.list.d/raspi.list + - /etc/apt/sources.list.d/*.list + - /etc/apt/sources.list.d/*.sources + loop_control: + loop_var: item + ignore_errors: yes + + # 2. Создаём основной sources.list + - name: Write /etc/apt/sources.list + copy: + content: "{{ sources_list_content }}" + dest: /etc/apt/sources.list + owner: root + group: root + mode: '0644' + + # 3. Если это Raspberry Pi – создаём raspi.list + - name: Check if system is Raspberry Pi + stat: + path: /etc/rpi-issue + register: rpi_check + + - name: Write /etc/apt/sources.list.d/raspi.list (only on Raspberry Pi) + copy: + content: "{{ raspi_list_content }}" + dest: /etc/apt/sources.list.d/raspi.list + owner: root + group: root + mode: '0644' + when: rpi_check.stat.exists + + # 4. Обновляем кэш APT + - name: Update APT cache + apt: + update_cache: yes + cache_valid_time: 3600 \ No newline at end of file