initial commit

This commit is contained in:
2026-04-12 23:24:13 +08:00
commit 7592af1c3a
55 changed files with 5051 additions and 0 deletions
@@ -0,0 +1,5 @@
---
- name: 重启 PostgreSQL
systemd:
name: "postgresql-{{ postgresql_version }}"
state: restarted
+73
View File
@@ -0,0 +1,73 @@
---
# roles/postgresql/tasks/main.yml
# PostgreSQL 安装与配置
- name: 禁用系统自带的 postgresql 模块
command: dnf module disable postgresql -y
register: pg_module_disable
changed_when: "'Nothing to do' not in pg_module_disable.stdout"
failed_when: false
- name: 安装 PostgreSQL 官方仓库 RPM
dnf:
name: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
state: present
disable_gpg_check: yes
- name: 安装 PostgreSQL {{ postgresql_version }}
dnf:
name:
- postgresql{{ postgresql_version }}-server
- postgresql{{ postgresql_version }}
- python3-psycopg2
state: present
- name: 检查 PostgreSQL 数据目录是否已初始化
stat:
path: "/var/lib/pgsql/{{ postgresql_version }}/data/PG_VERSION"
register: pg_data_dir
- name: 初始化 PostgreSQL 数据库集群
command: "/usr/pgsql-{{ postgresql_version }}/bin/postgresql-{{ postgresql_version }}-setup initdb"
when: not pg_data_dir.stat.exists
- name: 部署 pg_hba.conf
template:
src: pg_hba.conf.j2
dest: "/var/lib/pgsql/{{ postgresql_version }}/data/pg_hba.conf"
owner: postgres
group: postgres
mode: "0600"
notify: 重启 PostgreSQL
- name: 启用并启动 PostgreSQL 服务
systemd:
name: "postgresql-{{ postgresql_version }}"
state: started
enabled: yes
- name: 等待 PostgreSQL 就绪
wait_for:
port: 5432
delay: 2
timeout: 30
- name: 创建 Gitea 数据库用户
become: true
become_user: postgres
community.postgresql.postgresql_user:
name: "{{ gitea_db_user }}"
password: "{{ gitea_db_password }}"
state: present
no_log: true
- name: 创建 Gitea 数据库
become: true
become_user: postgres
community.postgresql.postgresql_db:
name: "{{ gitea_db_name }}"
owner: "{{ gitea_db_user }}"
encoding: UTF-8
lc_collate: en_US.UTF-8
lc_ctype: en_US.UTF-8
state: present
@@ -0,0 +1,15 @@
# PostgreSQL Client Authentication Configuration File
# ===================================================
# Managed by Ansible - DO NOT EDIT MANUALLY
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all postgres peer
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5