Files
Raspberry_awx/playbooks/APT_repositories_on_Raspberry.yml
T

55 lines
2.1 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
- 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