Добавить playbooks/APT_repositories_on_Raspberry.yml

This commit is contained in:
2026-08-21 14:53:26 +03:00
parent 86aeefa388
commit fa762928fd
@@ -0,0 +1,55 @@
---
- name: Automatically set up-to-date APT repositories on Raspberry Pi
hosts: all
become: yes
gather_facts: yes
vars:
# Определяем кодовое имя дистрибутива (bookworm, trixie, bullseye и т.д.)
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
# Содержимое для /etc/apt/sources.list.d/raspi.list (репозитории Raspberry Pi)
raspi_list_content: |
deb http://archive.raspberrypi.com/debian/ {{ distro_codename }} main
tasks:
# 1. Создаём резервные копии текущих файлов (с меткой времени)
- name: Backup current sources.list files
copy:
src: "{{ item }}"
dest: "{{ item }}.backup_{{ ansible_date_time.epoch }}"
remote_src: yes
loop:
- /etc/apt/sources.list
- /etc/apt/sources.list.d/raspi.list
ignore_errors: yes
# 2. Записываем новый sources.list напрямую из переменной
- name: Write new /etc/apt/sources.list
copy:
content: "{{ sources_list_content }}"
dest: /etc/apt/sources.list
owner: root
group: root
mode: '0644'
# 3. Записываем новый raspi.list напрямую из переменной
- name: Write new /etc/apt/sources.list.d/raspi.list
copy:
content: "{{ raspi_list_content }}"
dest: /etc/apt/sources.list.d/raspi.list
owner: root
group: root
mode: '0644'
# 4. Обновляем кэш APT (apt update)
- name: Update APT cache
apt:
update_cache: yes
cache_valid_time: 3600