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

157 lines
4.1 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
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
2022-04-09 13:30:32 +02:00
- name: Copy gitea_backup.sh script
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.template:
2022-04-09 13:30:32 +02:00
src: gitea_backup.sh.j2
2022-12-27 11:33:45 +01:00
dest: /usr/local/bin/gitea_backup.sh
2022-04-09 13:30:32 +02:00
owner: git
group: git
mode: 0775
- name: Create gitea-dumps directory
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.file:
2022-12-27 11:33:45 +01:00
path: /var/lib/gitea/gitea-dumps
state: directory
owner: git
group: git
mode: 0755
- name: Set today's string for zipfile name
2022-12-16 20:12:49 +01:00
ansible.builtin.set_fact:
today: "{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}"
2022-12-23 22:17:54 +01:00
- name: Ask to push latest gitea_dump zipfile
ansible.builtin.pause:
prompt: "Local path to latest gitea dump, so we can push it [leave empty to not push]"
2022-08-21 16:15:44 +02:00
echo: true
2022-12-23 22:17:54 +01:00
register: latest_gitea_dump_path
- name: Make sure the filename makes sense
ansible.builtin.assert:
that:
- "{{ latest_gitea_dump_path.user_input | basename }} == gitea-dump-{{ today }}.zip"
when: latest_gitea_dump_path.user_input != ''
2022-08-21 16:15:44 +02:00
2022-04-13 22:21:05 +02:00
- name: Push latest gitea_dump zipfile
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.copy:
2022-12-23 22:17:54 +01:00
src: "{{ latest_gitea_dump_path.user_input }}"
2022-12-27 11:33:45 +01:00
dest: "/var/lib/gitea/gitea-dumps/gitea-dump-{{ today }}.zip"
owner: git
group: git
mode: 0640
2022-12-23 22:17:54 +01:00
when: latest_gitea_dump_path.user_input != ''
- name: Deploy repos
become: true
become_user: git
2022-12-16 20:12:49 +01:00
ansible.builtin.command:
2022-12-27 11:33:45 +01:00
cmd: "/var/lib/gitea/gitea_backup.sh restore /var/lib/gitea/gitea-dumps/gitea-dump-{{ today }}.zip"
creates: /var/lib/gitea/gitea-repositories # when this dir exists, the command won't run, so we don't overwrite existing repos
2022-08-28 22:17:48 +02:00
2022-09-28 22:03:57 +02:00
- name: Setup gitea-backup crontab
become: true
2022-12-16 20:12:49 +01:00
ansible.builtin.copy:
2022-09-28 22:03:57 +02:00
src: gitea-backup.cron
dest: /etc/cron.d/gitea-backup
mode: 0644
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