Добавлена роль repo для автоматического добавления репозиториев

- Создана новая роль repo для добавления репозиториев на все ОС
- Добавлена поддержка Docker, PostgreSQL, Elasticsearch, Patroni репозиториев
- Реализована специальная поддержка российских дистрибутивов:
  - Astra Linux: добавлены репозитории Lab50 и debian-archive-keyring
  - Alt Linux: добавлены репозитории Sisyphus (alt-sisyphus, classic, contrib) и Autoimports
- Обновлена документация README.md с информацией о новой роли
- Обновлен .ansible-lint для подавления необходимых правил
- Автор: Сергей Антропов, https://devops.org.ru
This commit is contained in:
Сергей Антропов
2025-10-30 03:13:35 +03:00
parent a2316ae780
commit 23e1a6037b
25 changed files with 2495 additions and 1038 deletions

84
roles/repo/tasks/alt.yml Normal file
View File

@@ -0,0 +1,84 @@
---
# Задачи для Alt Linux
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
# Alt Linux использует apt и свои внутренние репозитории
- name: Обновить кэш пакетов Alt Linux
ansible.builtin.raw: apt-get update -qq
register: update_result
changed_when: update_result.rc == 0
failed_when: false
- name: Установить необходимые пакеты для работы с репозиториями в Alt Linux
ansible.builtin.raw: apt-get install -y ca-certificates curl gnupg || true
register: install_result
changed_when: install_result.rc == 0
failed_when: false
- name: Создать директорию для GPG ключей
ansible.builtin.file:
path: /usr/share/keyrings
state: directory
mode: '0755'
failed_when: false
- name: Получить и добавить Docker GPG ключ (используем ключ Debian)
ansible.builtin.raw: curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg || true
args:
creates: /usr/share/keyrings/docker-archive-keyring.gpg
changed_when: false
failed_when: false
- name: Попытаться добавить репозиторий Docker для Alt Linux
ansible.builtin.raw: echo "deb [arch={{ ansible_architecture }} signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian buster stable" > /etc/apt/sources.list.d/docker.list || true
changed_when: false
failed_when: false
when: ansible_architecture in ["amd64", "x86_64"]
- name: Проверить и добавить репозиторий Sisyphus (alt-sisyphus)
ansible.builtin.raw: grep -q "Sisyphus.*alt-sisyphus" /etc/apt/sources.list || echo "{{ alt_repos['sisyphus_repo'] }}" >> /etc/apt/sources.list
register: sisyphus_result
changed_when: sisyphus_result.rc == 0
failed_when: false
- name: Проверить и добавить репозиторий Sisyphus classic
ansible.builtin.raw: grep -q "Sisyphus.*classic" /etc/apt/sources.list || echo "{{ alt_repos['sisyphus_classic_repo'] }}" >> /etc/apt/sources.list
register: sisyphus_classic_result
changed_when: sisyphus_classic_result.rc == 0
failed_when: false
- name: Проверить и добавить репозиторий Sisyphus contrib
ansible.builtin.raw: grep -q "Sisyphus.*contrib" /etc/apt/sources.list || echo "rpm [alt] http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus x86_64 contrib" >> /etc/apt/sources.list
register: sisyphus_contrib_result
changed_when: sisyphus_contrib_result.rc == 0
failed_when: false
- name: Проверить и добавить репозиторий autoimports
ansible.builtin.raw: grep -q "autoimports" /etc/apt/sources.list || echo "{{ alt_repos['autoimports_repo'] }}" >> /etc/apt/sources.list
register: autoimports_result
changed_when: autoimports_result.rc == 0
failed_when: false
- name: Обновить кэш пакетов после добавления репозиториев
ansible.builtin.raw: apt-get update -qq
register: cache_update
changed_when: cache_update.rc == 0
failed_when: false
- name: Выполнить обновление пакетов Alt Linux
ansible.builtin.raw: apt-get upgrade -y -qq || true
register: upgrade_result
changed_when: upgrade_result.rc == 0
failed_when: false
- name: Информационное сообщение о репозиториях Alt Linux
ansible.builtin.debug:
msg: |
Роль repo выполнена для Alt Linux.
Добавлены репозитории:
- Sisyphus (alt-sisyphus) - rolling release с ежедневными обновлениями
- Sisyphus (classic) - классический репозиторий
- Autoimports - автоматически собранные свежие пакеты из GitHub/GitLab
ВНИМАНИЕ: Sisyphus может быть нестабилен, используйте осторожно.
PostgreSQL, Elasticsearch и Patroni обычно доступны в базовых репозиториях Alt Linux.

119
roles/repo/tasks/astra.yml Normal file
View File

@@ -0,0 +1,119 @@
---
# Задачи для Astra Linux
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
# Astra Linux основан на Debian, используем apt
- name: Установить необходимые пакеты для работы с репозиториями
ansible.builtin.apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
update_cache: yes
- name: Создать директорию для GPG ключей
ansible.builtin.file:
path: /usr/share/keyrings
state: directory
mode: '0755'
- name: Получить и добавить Docker GPG ключ (используем ключ Debian)
ansible.builtin.shell: |
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
args:
creates: /usr/share/keyrings/docker-archive-keyring.gpg
notify: "update apt cache"
- name: Добавить репозиторий Docker для Astra Linux
ansible.builtin.apt_repository:
repo: "{{ astra_repos['docker_repo'] }}"
state: present
filename: docker-ce
notify: "update apt cache"
- name: Получить и добавить PostgreSQL GPG ключ
ansible.builtin.shell: |
curl -fsSL {{ postgresql_gpg_url }} | gpg --dearmor -o /usr/share/keyrings/postgresql.gpg
args:
creates: /usr/share/keyrings/postgresql.gpg
notify: "update apt cache"
- name: Добавить репозиторий PostgreSQL для Astra Linux
ansible.builtin.apt_repository:
repo: "{{ astra_repos['postgresql_repo'] }}"
state: present
filename: postgresql
notify: "update apt cache"
- name: Получить и добавить Elasticsearch GPG ключ
ansible.builtin.shell: |
curl -fsSL {{ elasticsearch_gpg_url }} | gpg --dearmor -o /usr/share/keyrings/elasticsearch.gpg
args:
creates: /usr/share/keyrings/elasticsearch.gpg
notify: "update apt cache"
- name: Добавить репозиторий Elasticsearch для Astra Linux
ansible.builtin.apt_repository:
repo: "{{ astra_repos['elasticsearch_repo'] }}"
state: present
filename: elasticsearch
notify: "update apt cache"
- name: Получить скрипт установки Patroni repository для Debian/Ubuntu
ansible.builtin.get_url:
url: "https://packagecloud.io/install/repositories/patroni/patroni/script.deb.sh"
dest: /tmp/patroni-repo-install.sh
mode: '0755'
- name: Запустить скрипт установки Patroni repository
ansible.builtin.command: bash /tmp/patroni-repo-install.sh
args:
creates: /etc/apt/sources.list.d/patroni_patroni.list
notify: "update apt cache"
- name: Очистить временный файл установки Patroni
ansible.builtin.file:
path: /tmp/patroni-repo-install.sh
state: absent
- name: Установить debian-archive-keyring для поддержки Debian репозиториев
ansible.builtin.apt:
name: "{{ astra_repos['debian_archive_keyring'] }}"
state: present
notify: "update apt cache"
- name: Добавить ключ репозитория Лаборатории 50
ansible.builtin.shell: |
wget -qO - {{ astra_repos['lab50_key_url'] }} | apt-key add -
args:
creates: /etc/apt/trusted.gpg.d/lab50.gpg
notify: "update apt cache"
- name: Добавить репозиторий Лаборатории 50
ansible.builtin.apt_repository:
repo: "{{ astra_repos['lab50_repo'] }}"
state: present
filename: lab50
notify: "update apt cache"
- name: Добавить репозиторий с исходниками Лаборатории 50
ansible.builtin.apt_repository:
repo: "{{ astra_repos['lab50_src_repo'] }}"
state: present
filename: lab50-src
notify: "update apt cache"
- name: Обновить кэш пакетов после добавления всех репозиториев
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 0
- name: Выполнить обновление пакетов
ansible.builtin.apt:
upgrade: dist
update_cache: yes
autoremove: yes
autoclean: yes

View File

@@ -0,0 +1,96 @@
---
# Задачи для Debian/Ubuntu
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
- name: Установить необходимые пакеты для работы с репозиториями
ansible.builtin.apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
update_cache: yes
allow_unauthenticated: no
force_apt_get: yes
- name: Создать директорию для GPG ключей
ansible.builtin.file:
path: /usr/share/keyrings
state: directory
mode: '0755'
- name: Получить и добавить Docker GPG ключ
ansible.builtin.shell: |
curl -fsSL {{ docker_gpg_url }} | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
args:
creates: /usr/share/keyrings/docker-archive-keyring.gpg
notify: "update apt cache"
- name: Добавить репозиторий Docker для {{ os_version_id }}
ansible.builtin.apt_repository:
repo: "{{ debian_repos[os_version_id]['docker_repo'] }}"
state: present
filename: docker-ce
when: debian_repos is defined and os_version_id in debian_repos
notify: "update apt cache"
- name: Получить и добавить PostgreSQL GPG ключ
ansible.builtin.shell: |
curl -fsSL {{ postgresql_gpg_url }} | gpg --dearmor -o /usr/share/keyrings/postgresql.gpg
args:
creates: /usr/share/keyrings/postgresql.gpg
notify: "update apt cache"
- name: Добавить репозиторий PostgreSQL для {{ os_version_id }}
ansible.builtin.apt_repository:
repo: "{{ debian_repos[os_version_id]['postgresql_repo'] }}"
state: present
filename: postgresql
when: debian_repos is defined and os_version_id in debian_repos
notify: "update apt cache"
- name: Получить и добавить Elasticsearch GPG ключ
ansible.builtin.shell: |
curl -fsSL {{ elasticsearch_gpg_url }} | gpg --dearmor -o /usr/share/keyrings/elasticsearch.gpg
args:
creates: /usr/share/keyrings/elasticsearch.gpg
notify: "update apt cache"
- name: Добавить репозиторий Elasticsearch для {{ os_version_id }}
ansible.builtin.apt_repository:
repo: "{{ debian_repos[os_version_id]['elasticsearch_repo'] }}"
state: present
filename: elasticsearch
when: debian_repos is defined and os_version_id in debian_repos
notify: "update apt cache"
- name: Получить скрипт установки Patroni repository для Debian/Ubuntu
ansible.builtin.get_url:
url: "https://packagecloud.io/install/repositories/patroni/patroni/script.deb.sh"
dest: /tmp/patroni-repo-install.sh
mode: '0755'
- name: Запустить скрипт установки Patroni repository
ansible.builtin.command: bash /tmp/patroni-repo-install.sh
args:
creates: /etc/apt/sources.list.d/patroni_patroni.list
notify: "update apt cache"
- name: Очистить временный файл установки Patroni
ansible.builtin.file:
path: /tmp/patroni-repo-install.sh
state: absent
- name: Обновить кэш пакетов после добавления всех репозиториев
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 0
- name: Выполнить обновление пакетов
ansible.builtin.apt:
upgrade: dist
update_cache: yes
autoremove: yes
autoclean: yes

31
roles/repo/tasks/main.yml Normal file
View File

@@ -0,0 +1,31 @@
---
# Задачи для роли repo
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
- name: Определить семейство ОС для репозиториев
ansible.builtin.set_fact:
os_family: "{{ ansible_os_family }}"
distribution_lower: "{{ ansible_distribution | lower }}"
os_version_id: "{{ ansible_distribution | lower }}{{ ansible_distribution_major_version }}"
os_version_id_rhel: "{{ ansible_distribution | lower }}{{ ansible_distribution_major_version }}"
- name: Включить задачи для Debian/Ubuntu
ansible.builtin.include_tasks: debian.yml
when: os_family == "Debian" and ansible_distribution != "AstraLinux" and ansible_distribution != "Altlinux"
- name: Включить задачи для Astra Linux
ansible.builtin.include_tasks: astra.yml
when: ansible_distribution == "AstraLinux"
- name: Включить задачи для Alt Linux
ansible.builtin.include_tasks: alt.yml
when: ansible_distribution == "Altlinux"
- name: Включить задачи для RHEL/CentOS/AlmaLinux/Rocky
ansible.builtin.include_tasks: rhel.yml
when: os_family == "RedHat"
- name: Завершение настройки репозиториев
ansible.builtin.debug:
msg: "Роль repo успешно выполнена. Все необходимые репозитории добавлены и обновлены."

99
roles/repo/tasks/rhel.yml Normal file
View File

@@ -0,0 +1,99 @@
---
# Задачи для RHEL/CentOS/AlmaLinux/Rocky
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
- name: Установить необходимые пакеты для работы с репозиториями (yum)
ansible.builtin.package:
name: yum-utils
state: present
when: ansible_pkg_mgr == 'yum'
- name: Установить необходимые пакеты для работы с репозиториями (dnf)
ansible.builtin.package:
name: dnf-plugins-core
state: present
when: ansible_pkg_mgr == 'dnf'
- name: Установить EPEL repository
ansible.builtin.dnf:
name: epel-release
state: present
when: ansible_distribution in ['RedHat', 'Rocky', 'CentOS', 'AlmaLinux']
- name: Определить корректный ключ для RHEL/CentOS 8
ansible.builtin.set_fact:
rhel_key: "{{ rhel_repos['rhel8'] }}"
when: ansible_distribution_major_version == "8" and os_version_id in ["redhat8", "rhel8", "centos8", "almalinux8"]
- name: Определить корректный ключ для RHEL/CentOS 9
ansible.builtin.set_fact:
rhel_key: "{{ rhel_repos['rhel9'] }}"
when: ansible_distribution_major_version == "9" and os_version_id in ["redhat9", "rhel9", "centos9", "rocky9"]
- name: Добавить репозиторий Docker
ansible.builtin.yum_repository:
name: docker-ce
description: Docker CE Repository
baseurl: "{{ rhel_key['docker_baseurl'] }}"
gpgcheck: yes
gpgkey: "{{ rhel_key['docker_gpgkey'] }}"
enabled: yes
when: rhel_key is defined
notify: "update dnf cache"
- name: Добавить репозиторий PostgreSQL
ansible.builtin.yum_repository:
name: postgresql
description: PostgreSQL Official Repository
baseurl: "{{ rhel_key['postgresql_baseurl'] }}"
gpgcheck: yes
gpgkey: "{{ rhel_key['postgresql_gpgkey'] }}"
enabled: yes
when: rhel_key is defined
notify: "update dnf cache"
- name: Добавить репозиторий Elasticsearch
ansible.builtin.yum_repository:
name: elasticsearch
description: Elasticsearch Repository
baseurl: "{{ rhel_key['elasticsearch_baseurl'] }}"
gpgcheck: yes
gpgkey: "{{ rhel_key['elasticsearch_gpgkey'] }}"
enabled: yes
when: rhel_key is defined
notify: "update dnf cache"
- name: Получить скрипт установки Patroni repository для RHEL/CentOS
ansible.builtin.get_url:
url: "https://packagecloud.io/install/repositories/patroni/patroni/script.rpm.sh"
dest: /tmp/patroni-repo-install.sh
mode: '0755'
- name: Запустить скрипт установки Patroni repository
ansible.builtin.command: bash /tmp/patroni-repo-install.sh
args:
creates: /etc/yum.repos.d/patroni_patroni.repo
notify: "update dnf cache"
- name: Очистить временный файл установки Patroni
ansible.builtin.file:
path: /tmp/patroni-repo-install.sh
state: absent
- name: Обновить кэш пакетов после добавления всех репозиториев
ansible.builtin.command: "{{ ansible_pkg_mgr }} makecache"
register: cache_result
changed_when: "'Complete!' in cache_result.stdout or 'Metadata cache created.' in cache_result.stdout"
- name: Выполнить обновление пакетов через dnf
ansible.builtin.command: dnf upgrade -y
register: dnf_upgrade
changed_when: "'Complete!' in dnf_upgrade.stdout or 'Nothing to do.' not in dnf_upgrade.stdout"
when: ansible_pkg_mgr == "dnf"
- name: Выполнить обновление пакетов через yum
ansible.builtin.command: yum upgrade -y
register: yum_upgrade
changed_when: "'Complete!' in yum_upgrade.stdout or 'Nothing to do.' not in yum_upgrade.stdout"
when: ansible_pkg_mgr == "yum"