self-hosting/roles/gitea/tasks/main.yml

105 lines
2.5 KiB
YAML
Raw Normal View History

2022-04-07 21:00:33 +02:00
---
2022-06-25 14:48:38 +02:00
- name: Include vault variables
2022-12-16 20:12:49 +01:00
ansible.builtin.include_vars: vault.yml
2022-12-26 07:22:21 +01:00
- name: Include apache2 tasks
ansible.builtin.include_tasks: apache2.yml
2022-12-26 07:51:52 +01:00
- name: Include mariadb tasks
ansible.builtin.include_tasks: mariadb.yml
- name: Include unix tasks
ansible.builtin.include_tasks: unix.yml
2022-04-07 21:07:45 +02:00
- name: Include binary tasks
ansible.builtin.include_tasks: binary.yml
2022-04-07 23:18:20 +02:00
- name: Include backup tasks
ansible.builtin.include_tasks: backup.yml
2022-06-08 22:14:29 +02:00
- name: Copy /etc/systemd/system/gitea.service
2022-04-07 23:18:20 +02:00
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.copy:
2022-04-07 23:18:20 +02:00
src: gitea.service
dest: /etc/systemd/system/gitea.service
owner: root
group: root
mode: 0644
notify:
- Reload systemd daemon
- Start gitea service
2022-04-09 13:30:32 +02:00
- name: Copy /etc/gitea/app.ini
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.template:
src: app.ini.j2
dest: /etc/gitea/app.ini
owner: git
group: git
mode: 0640
notify:
2022-10-01 00:41:21 +02:00
- Restart gitea service
- name: Make sure systemd daemon is reloaded
2022-12-16 20:12:49 +01:00
ansible.builtin.meta: flush_handlers
2022-04-09 13:30:32 +02:00
- name: Make sure gitea is running
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.systemd:
name: gitea
state: started
enabled: true
2022-12-26 07:14:02 +01:00
# fail2ban tasks need the gitea log file, which should be created when gitea runs
- name: Include fail2ban tasks
ansible.builtin.include_tasks: fail2ban.yml
- name: Include repos tasks
ansible.builtin.include_tasks: repos.yml
2022-08-28 22:17:48 +02:00
2022-12-23 21:35:04 +01:00
- name: Setup logrotate for gitea logs
become: true
ansible.builtin.copy:
src: gitea.logrotate
dest: /etc/logrotate.d/gitea
owner: root
group: root
mode: 0644
- name: Generate SSH keys for git
become: true
become_user: git
2022-12-16 20:12:49 +01:00
community.crypto.openssh_keypair:
path: ~/.ssh/id_rsa
type: rsa
comment: "git@{{ ansible_fqdn }}"
register: ssh_key
- name: Get previously added SSH keys
2022-12-16 20:12:49 +01:00
ansible.builtin.uri:
url: https://git.tunuifranken.info/api/v1/user/keys
method: GET
user: "{{ gitea_user }}"
password: "{{ gitea_pass }}"
force_basic_auth: true
register: present_ssh_keys
- name: List SSH fingerprints
2022-12-16 20:12:49 +01:00
ansible.builtin.set_fact:
present_ssh_fingerprints: "{{ present_ssh_keys.json | map(attribute='fingerprint') }}"
- name: Add SSH key using Gitea's API
2022-12-16 20:12:49 +01:00
ansible.builtin.uri:
url: https://git.tunuifranken.info/api/v1/user/keys
method: POST
user: "{{ gitea_user }}"
password: "{{ gitea_pass }}"
force_basic_auth: true
status_code: 201
body_format: json
body:
key: "{{ ssh_key.public_key | trim }}"
read_only: false
title: "{{ ssh_key.comment | trim }}"
when: ssh_key.fingerprint not in present_ssh_fingerprints