Skip to content

Commit 9a4b561

Browse files
committed
feat(telco-kpis): Add Gitea role for test report publishing
Implement Gitea deployment and report publishing infrastructure for hosting Telco-KPIs test reports with vault integration and retention policies. ## Problem Telco-KPIs test reports need centralized hosting accessible to test engineers and stakeholders. Reports generated on bastion hosts need automated publishing to a Git-based repository system with retention management. ## Solution Created `gitea` Ansible role for deploying Gitea server and publishing test reports as Markdown files with compressed artifacts. **Role: playbooks/telco-kpis/roles/gitea/** ## Features **Deployment:** - Podman-based Gitea server deployment on bastion - SQLite database with automatic migration handling - Firewall configuration (port 3000) - Accessibility checking instead of container existence - Admin user creation with API token management **Report Publishing:** - Creates organization and repositories automatically - Publishes Markdown reports via Gitea API - Uploads compressed tarball as release artifact - Updates repository README with latest report links - Retention policy: keeps last 15 reports, removes older ones **Vault Integration:** - Gitea credentials stored in Ansible vault - Secure API token management - Credential validation before operations ## Implementation Details **Role Structure:** - `tasks/main.yml` - Entry point with operation dispatch - `tasks/deploy.yml` - Gitea server deployment - `tasks/initialize.yml` - Initial configuration and admin setup - `tasks/validate-credentials.yml` - Vault credential validation - `tasks/create-repository.yml` - Repository creation - `tasks/publish-report.yml` - Report publishing workflow - `defaults/main.yml` - Default variables - `templates/README.md.j2` - Repository README template **Task Operations:** - `gitea_operation: deploy` - Deploy and initialize Gitea server - `gitea_operation: publish` - Publish test report - `gitea_operation: validate` - Validate vault credentials ## Usage **Deploy Gitea:** ```yaml - name: Deploy Gitea server ansible.builtin.include_role: name: gitea vars: gitea_operation: deploy gitea_vault_org: telco-kpis ``` **Publish report:** ```yaml - name: Publish test report ansible.builtin.include_role: name: gitea vars: gitea_operation: publish gitea_vault_org: telco-kpis gitea_vault_repo: hlxcl7-reports gitea_report_file: /path/to/report.md gitea_artifact_file: /path/to/artifacts.tar.gz ``` ## Key Features **Firewall Management:** - Detects firewalld vs. iptables - Adds port 3000 rule if not present - Handles both firewall backends **Database Migration:** - Waits for database initialization on first run - Handles migration errors gracefully - Retries admin user creation after migration **Repository Retention:** - Keeps last 15 reports per repository - Automatically deletes older reports - Prevents unbounded repository growth **Error Handling:** - Comprehensive API error checking - Retries for transient failures - Detailed error messages ## Benefits - Centralized test report hosting - Automated report publishing workflow - Secure credential management via vault - Retention policy prevents storage bloat - Accessible web UI for stakeholders - Git-based versioning of reports ## Integration Used by `playbooks/telco-kpis/generate-report.yml` to publish aggregated test reports from all Telco-KPIs tests (node-info, BIOS validation, performance tests, deployment timeline). Related: Telco-KPIs test infrastructure, report generation system Signed-off-by: Carlos Cardenosa <ccardeno@redhat.com>
1 parent a086393 commit 9a4b561

9 files changed

Lines changed: 1275 additions & 0 deletions

File tree

playbooks/telco-kpis/roles/gitea/README.md

Lines changed: 437 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# Gitea Configuration Defaults
3+
gitea_container_name: gitea
4+
gitea_http_port: 3000
5+
gitea_ssh_port: 2222
6+
gitea_domain: "bastion.kni-qe-71.telco-kpis.rdu3.redhat.com"
7+
gitea_root_url: "http://{{ gitea_domain }}:{{ gitea_http_port }}/"
8+
9+
# Admin credentials from vault (defaults to bastion user credentials)
10+
# These are typically provided by ansible_group_bastions vault or bastion host_vars
11+
gitea_admin_user: "{{ ansible_user | default('telcov10n') }}"
12+
gitea_admin_password: "{{ ansible_password | default(lookup('env', 'BASTION_PASSWORD') | default('', true)) }}"
13+
gitea_admin_email: "{{ gitea_admin_user }}@localhost"
14+
15+
gitea_data_dir: "{{ ansible_env.HOME }}/gitea/data"
16+
gitea_repo_name: telco-kpis-reports
17+
gitea_repo_description: "Telco KPIs Test Reports Archive"
18+
gitea_image: "docker.io/gitea/gitea:latest"
19+
20+
# API endpoints
21+
gitea_api_base: "{{ gitea_root_url }}api/v1"
22+
gitea_install_url: "{{ gitea_root_url }}"
23+
24+
# Development mode flag (passed from playbook)
25+
development_mode: false
26+
27+
# Repository retention policy
28+
gitea_report_retention_days: 7 # Keep reports for last 7 days
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# Create telco-kpis-reports repository if it doesn't exist
3+
4+
- name: Check if repository exists
5+
ansible.builtin.uri:
6+
url: "{{ gitea_api_base }}/repos/{{ gitea_admin_user }}/{{ gitea_repo_name }}"
7+
method: GET
8+
user: "{{ gitea_admin_user }}"
9+
password: "{{ gitea_admin_password }}"
10+
force_basic_auth: true
11+
status_code: [200, 404]
12+
register: repo_check
13+
14+
- name: Display repository status
15+
ansible.builtin.debug:
16+
msg: "Repository exists: {{ repo_check.status == 200 }}"
17+
18+
- name: Create repository
19+
when: repo_check.status == 404
20+
block:
21+
- name: Create telco-kpis-reports repository via API
22+
ansible.builtin.uri:
23+
url: "{{ gitea_api_base }}/user/repos"
24+
method: POST
25+
user: "{{ gitea_admin_user }}"
26+
password: "{{ gitea_admin_password }}"
27+
force_basic_auth: true
28+
body_format: json
29+
body:
30+
name: "{{ gitea_repo_name }}"
31+
description: "{{ gitea_repo_description }}"
32+
private: false
33+
auto_init: true
34+
default_branch: main
35+
readme: "Default"
36+
status_code: [201, 422] # 422 if already exists
37+
register: repo_create
38+
39+
- name: Display repository creation result
40+
ansible.builtin.debug:
41+
msg: "Repository created: {{ repo_create.status == 201 }}"
42+
43+
- name: Wait for repository initialization
44+
ansible.builtin.pause:
45+
seconds: 5
46+
when: repo_create.status == 201
47+
48+
- name: Get repository clone URL
49+
ansible.builtin.set_fact:
50+
gitea_repo_http_url: "http://{{ gitea_admin_user }}:{{ gitea_admin_password }}@{{ gitea_domain }}:{{ gitea_http_port }}/{{ gitea_admin_user }}/{{ gitea_repo_name }}.git"
51+
gitea_repo_web_url: "{{ gitea_root_url }}{{ gitea_admin_user }}/{{ gitea_repo_name }}"
52+
53+
- name: Display repository URLs
54+
ansible.builtin.debug:
55+
msg:
56+
- "Repository Web URL: {{ gitea_repo_web_url }}"
57+
- "Repository Clone URL: http://{{ gitea_domain }}:{{ gitea_http_port }}/{{ gitea_admin_user }}/{{ gitea_repo_name }}.git"
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
# Deploy Gitea container on bastion if not already running
3+
4+
- name: Check if Gitea is accessible via localhost
5+
ansible.builtin.uri:
6+
url: "http://localhost:{{ gitea_http_port }}/"
7+
method: GET
8+
status_code: 200
9+
validate_certs: false
10+
register: gitea_accessible
11+
failed_when: false
12+
changed_when: false
13+
14+
- name: Check if firewalld is running
15+
ansible.builtin.systemd:
16+
name: firewalld
17+
register: firewalld_check
18+
failed_when: false
19+
become: true
20+
21+
- name: Check if Gitea HTTP port is open in firewall
22+
ansible.builtin.shell: firewall-cmd --list-ports | grep -q "{{ gitea_http_port }}/tcp"
23+
register: http_port_open
24+
failed_when: false
25+
changed_when: false
26+
become: true
27+
when:
28+
- firewalld_check.status is defined
29+
- firewalld_check.status.ActiveState == "active"
30+
31+
- name: Check if Gitea SSH port is open in firewall
32+
ansible.builtin.shell: firewall-cmd --list-ports | grep -q "{{ gitea_ssh_port }}/tcp"
33+
register: ssh_port_open
34+
failed_when: false
35+
changed_when: false
36+
become: true
37+
when:
38+
- firewalld_check.status is defined
39+
- firewalld_check.status.ActiveState == "active"
40+
41+
- name: Set Gitea deployment needed flag
42+
ansible.builtin.set_fact:
43+
gitea_deployment_needed: "{{ (gitea_accessible.status is not defined or gitea_accessible.status != 200) or (firewalld_check.status is defined and firewalld_check.status.ActiveState == 'active' and (http_port_open.rc != 0 or ssh_port_open.rc != 0)) }}"
44+
45+
- name: Display Gitea status
46+
ansible.builtin.debug:
47+
msg: "{{ 'Gitea is running and firewall configured - skipping deployment' if not gitea_deployment_needed else 'Gitea deployment or firewall configuration needed' }}"
48+
49+
- name: Deploy Gitea
50+
when: gitea_deployment_needed
51+
block:
52+
- name: Configure firewall rules
53+
when:
54+
- firewalld_check.status is defined
55+
- firewalld_check.status.ActiveState == "active"
56+
- http_port_open.rc != 0 or ssh_port_open.rc != 0
57+
block:
58+
- name: Open Gitea HTTP port in firewall
59+
ansible.posix.firewalld:
60+
port: "{{ gitea_http_port }}/tcp"
61+
permanent: true
62+
state: enabled
63+
immediate: true
64+
become: true
65+
66+
- name: Open Gitea SSH port in firewall
67+
ansible.posix.firewalld:
68+
port: "{{ gitea_ssh_port }}/tcp"
69+
permanent: true
70+
state: enabled
71+
immediate: true
72+
become: true
73+
74+
- name: Display firewall configuration status
75+
ansible.builtin.debug:
76+
msg: "Firewall configured: ports 3000/tcp and 2222/tcp opened"
77+
78+
- name: Deploy or redeploy Gitea container
79+
when: gitea_accessible.status is not defined or gitea_accessible.status != 200
80+
block:
81+
- name: Check if Gitea container exists
82+
ansible.builtin.command: podman ps -a --format json
83+
register: podman_containers
84+
changed_when: false
85+
86+
- name: Parse container list
87+
ansible.builtin.set_fact:
88+
gitea_container_exists: "{{ (podman_containers.stdout | from_json) | selectattr('Names', 'contains', gitea_container_name) | list | length > 0 }}"
89+
90+
- name: Remove existing broken Gitea container
91+
ansible.builtin.command: podman rm -f {{ gitea_container_name }}
92+
when: gitea_container_exists
93+
register: remove_result
94+
changed_when: remove_result.rc == 0
95+
96+
- name: Create Gitea data directory
97+
ansible.builtin.file:
98+
path: "{{ gitea_data_dir }}"
99+
state: directory
100+
mode: '0755'
101+
102+
- name: Pull Gitea container image
103+
ansible.builtin.command: podman pull {{ gitea_image }}
104+
register: pull_result
105+
changed_when: "'Downloaded newer image' in pull_result.stdout or 'Copying blob' in pull_result.stderr"
106+
107+
- name: Deploy Gitea container
108+
ansible.builtin.command: >
109+
podman run -d
110+
--name {{ gitea_container_name }}
111+
-p {{ gitea_http_port }}:3000
112+
-p {{ gitea_ssh_port }}:22
113+
-v {{ gitea_data_dir }}:/data:Z
114+
-e USER_UID={{ ansible_user_uid }}
115+
-e USER_GID={{ ansible_user_gid }}
116+
-e GITEA__database__DB_TYPE=sqlite3
117+
-e GITEA__database__PATH=/data/gitea/gitea.db
118+
-e GITEA__server__DOMAIN={{ gitea_domain }}
119+
-e GITEA__server__ROOT_URL={{ gitea_root_url }}
120+
-e GITEA__server__SSH_DOMAIN={{ gitea_domain }}
121+
-e GITEA__server__SSH_PORT={{ gitea_ssh_port }}
122+
-e GITEA__service__DISABLE_REGISTRATION=true
123+
-e GITEA__repository__DEFAULT_BRANCH=main
124+
--restart=always
125+
{{ gitea_image }}
126+
register: deploy_result
127+
changed_when: deploy_result.rc == 0
128+
129+
- name: Wait for Gitea to start
130+
ansible.builtin.uri:
131+
url: "http://localhost:{{ gitea_http_port }}/"
132+
method: GET
133+
status_code: 200
134+
validate_certs: false
135+
register: gitea_health
136+
until: gitea_health.status == 200
137+
retries: 30
138+
delay: 2
139+
140+
- name: Display Gitea deployment status
141+
ansible.builtin.debug:
142+
msg: "Gitea is accessible at {{ gitea_root_url }}"

0 commit comments

Comments
 (0)