添加 Gitea APT 仓库配置功能和完整文档系统

- 新增 gitea_repo_setup.yaml playbook 用于管理 Gitea APT 仓库
- 支持删除旧源、下载 GPG 密钥、配置新源和自动更新 APT 缓存
- 添加仓库配置架构文档和使用指南
- 采用部分参数化设计,支持自定义仓库 URL 和所有者
This commit is contained in:
2025-12-25 11:47:18 +08:00
parent a6399d1bce
commit 18c6780028
3 changed files with 164 additions and 0 deletions

88
gitea_repo_setup.yaml Normal file
View File

@@ -0,0 +1,88 @@
---
- name: Gitea APT 仓库配置脚本
hosts: all
become: yes
vars:
# 可配置参数
repo_url: "https://gitea.bcde.io"
repo_owner: "wangdefa"
# 固定路径配置
old_source_file: "/etc/apt/sources.list.d/xxxigcc.list"
new_source_file: "/etc/apt/sources.list.d/{{ repo_owner }}.list"
keyrings_dir: "/etc/apt/keyrings"
key_file: "{{ keyrings_dir }}/gitea-{{ repo_owner }}.asc"
key_url: "{{ repo_url }}/api/packages/{{ repo_owner }}/debian/repository.key"
tasks:
- name: 检查旧的软件源文件是否存在
ansible.builtin.stat:
path: "{{ old_source_file }}"
register: old_source_stat
- name: 删除旧的软件源文件
ansible.builtin.file:
path: "{{ old_source_file }}"
state: absent
when: old_source_stat.stat.exists
register: old_source_removed
- name: 显示旧源文件删除结果
ansible.builtin.debug:
msg: "{{ '已删除旧的软件源文件: ' + old_source_file if old_source_stat.stat.exists else '旧的软件源文件不存在,跳过删除' }}"
- name: 确保 keyrings 目录存在
ansible.builtin.file:
path: "{{ keyrings_dir }}"
state: directory
mode: '0755'
register: keyrings_dir_created
- name: 显示 keyrings 目录状态
ansible.builtin.debug:
msg: "keyrings 目录已确保存在: {{ keyrings_dir }}"
- name: 下载 GPG 密钥
ansible.builtin.get_url:
url: "{{ key_url }}"
dest: "{{ key_file }}"
mode: '0644'
force: yes
register: key_downloaded
- name: 显示密钥下载结果
ansible.builtin.debug:
msg: "GPG 密钥已下载到: {{ key_file }}"
- name: 创建新的软件源配置
ansible.builtin.copy:
content: "deb [signed-by={{ key_file }}] {{ repo_url }}/api/packages/{{ repo_owner }}/debian stable main\n"
dest: "{{ new_source_file }}"
mode: '0644'
register: source_created
- name: 显示软件源配置结果
ansible.builtin.debug:
msg: "新的软件源配置已创建: {{ new_source_file }}"
- name: 更新 APT 软件包缓存
ansible.builtin.apt:
update_cache: yes
register: apt_update
changed_when: apt_update.cache_updated
- name: 显示 APT 更新结果
ansible.builtin.debug:
msg: "APT 软件包缓存已更新"
- name: 显示操作总结
ansible.builtin.debug:
msg: |
操作完成总结:
- 旧源文件: {{ old_source_file }} {{ '(已删除)' if old_source_stat.stat.exists else '(不存在)' }}
- keyrings 目录: {{ keyrings_dir }} (已确保存在)
- GPG 密钥: {{ key_file }} (已下载)
- 新源文件: {{ new_source_file }} (已创建)
- 源配置内容: deb [signed-by={{ key_file }}] {{ repo_url }}/api/packages/{{ repo_owner }}/debian stable main
- APT 缓存: 已更新