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-04-07 22:34:22 +02:00
|
|
|
|
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
|
|
|
|
|
2022-12-27 10:51:38 +01:00
|
|
|
- name: Include unix tasks
|
|
|
|
ansible.builtin.include_tasks: unix.yml
|
2022-04-07 21:07:45 +02:00
|
|
|
|
2022-04-07 23:18:20 +02:00
|
|
|
- name: Find latest gitea version
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.uri:
|
2022-04-07 23:18:20 +02:00
|
|
|
url: https://dl.gitea.io/gitea/version.json
|
|
|
|
register: gitea_binary
|
|
|
|
|
2022-04-09 13:52:53 +02:00
|
|
|
- name: Find if latest gitea version is installed
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.stat:
|
2022-12-27 11:33:45 +01:00
|
|
|
path: "/var/lib/gitea/gitea-{{ gitea_binary.json.latest.version }}"
|
2022-04-09 13:52:53 +02:00
|
|
|
register: latest_gitea_binary
|
|
|
|
|
2022-04-07 23:18:20 +02:00
|
|
|
- name: Set gitea binary architecture to amd64
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.set_fact:
|
2022-04-07 23:18:20 +02:00
|
|
|
gitea_binary_arch: amd64
|
|
|
|
when: ansible_facts['architecture'] == 'x86_64'
|
|
|
|
|
|
|
|
- name: Set gitea binary architecture to arm-6
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.set_fact:
|
2022-04-09 13:03:23 +02:00
|
|
|
gitea_binary_arch: arm-6
|
2022-04-07 23:18:20 +02:00
|
|
|
when: ansible_facts['architecture'] != 'x86_64'
|
|
|
|
|
|
|
|
- name: Get latest gitea binary
|
|
|
|
become: true
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.get_url:
|
2022-04-07 23:18:20 +02:00
|
|
|
url: "https://dl.gitea.io/gitea/{{ gitea_binary.json.latest.version }}/gitea-{{ gitea_binary.json.latest.version }}-linux-{{ gitea_binary_arch }}"
|
2022-12-27 11:33:45 +01:00
|
|
|
dest: "/var/lib/gitea/gitea-{{ gitea_binary.json.latest.version }}"
|
2022-04-07 23:18:20 +02:00
|
|
|
owner: git
|
|
|
|
group: git
|
|
|
|
mode: 0664
|
2022-04-09 13:52:53 +02:00
|
|
|
when: not latest_gitea_binary.stat.exists
|
2022-04-09 11:04:23 +02:00
|
|
|
notify:
|
2022-04-09 12:51:52 +02:00
|
|
|
- Receive gitea pgp key
|
|
|
|
- Download gitea asc file
|
|
|
|
- Verify gitea binary with gpg
|
2022-04-07 23:18:20 +02:00
|
|
|
|
2022-04-09 11:04:23 +02:00
|
|
|
- name: Verify downloaded binary
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.meta: flush_handlers
|
2022-04-08 00:10:43 +02:00
|
|
|
|
2022-04-07 23:18:20 +02:00
|
|
|
- name: Copy gitea binary to global location
|
|
|
|
become: true
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.copy:
|
2022-12-27 11:33:45 +01:00
|
|
|
src: "/var/lib/gitea/gitea-{{ gitea_binary.json.latest.version }}"
|
2022-04-07 23:18:20 +02:00
|
|
|
dest: /usr/local/bin/gitea
|
|
|
|
remote_src: true
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
|
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
|
|
|
|
2022-06-08 22:18:12 +02:00
|
|
|
- name: Copy /etc/gitea/app.ini
|
|
|
|
become: true
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.template:
|
2022-06-08 22:18:12 +02:00
|
|
|
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
|
2022-06-08 22:18:12 +02:00
|
|
|
|
2022-04-10 12:44:11 +02:00
|
|
|
- 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
|
|
|
|
2022-04-10 12:44:11 +02:00
|
|
|
- name: Make sure gitea is running
|
|
|
|
become: true
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.systemd:
|
2022-04-10 12:44:11 +02:00
|
|
|
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
|
2022-04-10 13:33:00 +02:00
|
|
|
|
|
|
|
- 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
|
2022-04-10 13:33:00 +02:00
|
|
|
state: directory
|
|
|
|
owner: git
|
|
|
|
group: git
|
|
|
|
mode: 0755
|
|
|
|
|
2022-06-08 22:31:46 +02:00
|
|
|
- name: Set today's string for zipfile name
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.set_fact:
|
2022-06-08 22:31:46 +02:00
|
|
|
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
|
2022-04-10 13:33:00 +02:00
|
|
|
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"
|
2022-04-10 13:33:00 +02:00
|
|
|
owner: git
|
|
|
|
group: git
|
|
|
|
mode: 0640
|
2022-12-23 22:17:54 +01:00
|
|
|
when: latest_gitea_dump_path.user_input != ''
|
2022-04-10 13:33:00 +02:00
|
|
|
|
|
|
|
- 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-10-01 01:40:20 +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
|
|
|
|
|
2022-10-01 01:40:20 +02:00
|
|
|
- name: Generate SSH keys for git
|
|
|
|
become: true
|
|
|
|
become_user: git
|
2022-12-16 20:12:49 +01:00
|
|
|
community.crypto.openssh_keypair:
|
2022-10-01 01:40:20 +02:00
|
|
|
path: ~/.ssh/id_rsa
|
|
|
|
type: rsa
|
|
|
|
comment: "git@{{ ansible_fqdn }}"
|
|
|
|
register: ssh_key
|
|
|
|
|
2022-10-01 11:47:15 +02:00
|
|
|
- name: Get previously added SSH keys
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.uri:
|
2022-10-01 11:47:15 +02:00
|
|
|
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:
|
2022-10-01 11:47:15 +02:00
|
|
|
present_ssh_fingerprints: "{{ present_ssh_keys.json | map(attribute='fingerprint') }}"
|
|
|
|
|
2022-10-01 01:40:20 +02:00
|
|
|
- name: Add SSH key using Gitea's API
|
2022-12-16 20:12:49 +01:00
|
|
|
ansible.builtin.uri:
|
2022-10-01 01:40:20 +02:00
|
|
|
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 }}"
|
2022-10-01 11:47:15 +02:00
|
|
|
when: ssh_key.fingerprint not in present_ssh_fingerprints
|