2023-04-29 00:30:47 +02:00
|
|
|
# - name: Install Dependencies
|
|
|
|
# apt:
|
|
|
|
# pkg:
|
|
|
|
# - apparmor
|
|
|
|
# - docker.io
|
|
|
|
# - python3-docker
|
2022-10-14 15:08:14 +02:00
|
|
|
|
2023-05-01 22:38:08 +02:00
|
|
|
- name: Ensure git user exists
|
2022-11-08 11:46:39 +01:00
|
|
|
ansible.builtin.user:
|
|
|
|
name: git
|
|
|
|
register: git_user
|
|
|
|
|
2024-06-03 14:02:44 +02:00
|
|
|
- name: Ensure Gitea directories exist
|
2023-04-29 00:30:47 +02:00
|
|
|
ansible.builtin.file:
|
2024-06-03 14:02:44 +02:00
|
|
|
path: "{{ item }}"
|
2023-02-06 12:50:22 +01:00
|
|
|
state: directory
|
|
|
|
owner: root
|
2023-04-29 00:30:47 +02:00
|
|
|
mode: "755"
|
2024-06-03 14:02:44 +02:00
|
|
|
with_items: ["/opt/gitea", "/var/lib/gitea"]
|
2023-02-06 12:50:22 +01:00
|
|
|
|
2024-06-03 14:21:33 +02:00
|
|
|
- name: Ensure data and config directories exist
|
2023-04-29 00:30:47 +02:00
|
|
|
ansible.builtin.file:
|
2024-06-03 14:21:33 +02:00
|
|
|
path: "/var/lib/gitea/{{ item }}"
|
2022-10-14 15:08:14 +02:00
|
|
|
state: directory
|
2022-11-08 11:46:39 +01:00
|
|
|
owner: "{{ git_user.uid }}"
|
|
|
|
group: "{{ git_user.group }}"
|
2023-04-29 00:30:47 +02:00
|
|
|
mode: "700"
|
2024-06-03 14:21:33 +02:00
|
|
|
recurse: true
|
|
|
|
with_items: ["data", "config"]
|
2022-10-14 15:08:14 +02:00
|
|
|
|
2023-05-01 22:38:08 +02:00
|
|
|
- name: Ensure docker daemon is started
|
2023-04-29 00:30:47 +02:00
|
|
|
ansible.builtin.systemd:
|
2022-10-14 15:08:14 +02:00
|
|
|
name: docker
|
2023-04-29 00:30:47 +02:00
|
|
|
enabled: true
|
2022-10-14 15:08:14 +02:00
|
|
|
state: started
|
|
|
|
|
2023-07-06 11:37:56 +02:00
|
|
|
- name: Ensure old backups will get deleted
|
|
|
|
ansible.builtin.cron:
|
|
|
|
name: gitea backup cleanup
|
|
|
|
minute: "0"
|
|
|
|
hour: "8"
|
|
|
|
user: root
|
2024-04-11 13:41:46 +02:00
|
|
|
job: find /var/backups -path '/var/backups/gitea-*' -mtime +7 -type f -exec rm {} +
|
2023-07-06 11:37:56 +02:00
|
|
|
cron_file: gitea-backup-cleanup
|
|
|
|
|
2023-04-29 21:52:00 +02:00
|
|
|
- name: Check if environment.env will get changed
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: environment.env.j2
|
|
|
|
dest: "/opt/gitea/environment.env"
|
|
|
|
owner: root
|
|
|
|
mode: "600"
|
|
|
|
register: env_diff
|
|
|
|
check_mode: true
|
2023-04-29 20:37:01 +02:00
|
|
|
notify:
|
2023-04-29 21:52:00 +02:00
|
|
|
- Backup Gitea
|
2023-02-06 12:50:22 +01:00
|
|
|
|
2023-04-29 21:52:00 +02:00
|
|
|
- name: Check if docker-compose.yaml will get changed
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: docker-compose.yaml.j2
|
|
|
|
dest: /opt/gitea/docker-compose.yaml
|
|
|
|
owner: root
|
|
|
|
mode: "600"
|
|
|
|
register: docker_compose_diff
|
|
|
|
check_mode: true
|
|
|
|
notify:
|
|
|
|
- Backup Gitea
|
|
|
|
|
2023-05-01 22:38:08 +02:00
|
|
|
- name: Execute handlers before changing configfiles
|
2023-04-29 22:49:54 +02:00
|
|
|
ansible.builtin.meta: flush_handlers
|
2023-04-29 20:37:01 +02:00
|
|
|
|
2023-05-01 22:38:08 +02:00
|
|
|
- name: Upload environment.env
|
2023-04-29 20:37:01 +02:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: environment.env.j2
|
|
|
|
dest: "/opt/gitea/environment.env"
|
|
|
|
owner: root
|
|
|
|
mode: "600"
|
2023-04-29 22:22:03 +02:00
|
|
|
notify:
|
|
|
|
- Ensure Gitea is restarted
|
2023-05-01 02:02:56 +02:00
|
|
|
- Wait until Gitea is up
|
2023-04-29 20:37:01 +02:00
|
|
|
|
|
|
|
- name: Upload docker-compose.yaml
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: docker-compose.yaml.j2
|
|
|
|
dest: /opt/gitea/docker-compose.yaml
|
|
|
|
owner: root
|
|
|
|
mode: "600"
|
|
|
|
notify:
|
2023-05-01 22:38:08 +02:00
|
|
|
- Output docker compose state
|
2023-04-29 22:22:03 +02:00
|
|
|
- Ensure Gitea is restarted
|
2023-05-01 02:02:56 +02:00
|
|
|
- Wait until Gitea is up
|