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
|
|
|
|
2022-11-08 11:46:39 +01:00
|
|
|
- name: Create git USER
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: git
|
|
|
|
register: git_user
|
|
|
|
|
2023-02-06 12:50:22 +01:00
|
|
|
- name: Create Gitea
|
2023-04-29 00:30:47 +02:00
|
|
|
ansible.builtin.file:
|
2023-02-06 12:50:22 +01:00
|
|
|
path: "/opt/gitea"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
2023-04-29 00:30:47 +02:00
|
|
|
mode: "755"
|
2023-02-06 12:50:22 +01:00
|
|
|
|
2022-10-14 15:08:14 +02:00
|
|
|
- name: Create Data Directory
|
2023-04-29 00:30:47 +02:00
|
|
|
ansible.builtin.file:
|
2023-02-06 11:57:58 +01:00
|
|
|
path: "/opt/gitea/data"
|
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"
|
2022-10-14 15:08:14 +02:00
|
|
|
|
|
|
|
- name: Create Config Directory
|
2023-04-29 00:30:47 +02:00
|
|
|
ansible.builtin.file:
|
2023-02-06 11:57:58 +01:00
|
|
|
path: "/opt/gitea/config"
|
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"
|
2022-10-14 15:08:14 +02:00
|
|
|
|
|
|
|
- name: Start Docker Daemon
|
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-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
|
|
|
|
|
|
|
|
- name: Execute Handlers before changing configfiles
|
|
|
|
meta: flush_handlers
|
2023-04-29 20:37:01 +02:00
|
|
|
|
|
|
|
- name: Upload Environment File
|
|
|
|
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
|
|
|
|
- Check Gitea HTTP Response
|
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:
|
|
|
|
- Output Docker Compose State
|
2023-04-29 22:22:03 +02:00
|
|
|
- Ensure Gitea is restarted
|
|
|
|
- Check Gitea HTTP Response
|
2023-04-28 23:42:01 +02:00
|
|
|
|
2023-04-29 22:22:03 +02:00
|
|
|
- name: Update Config
|
2023-04-28 23:42:01 +02:00
|
|
|
block:
|
2023-04-29 22:22:03 +02:00
|
|
|
- name:
|
|
|
|
meta: flush_handlers
|
2023-04-28 23:42:01 +02:00
|
|
|
|
|
|
|
rescue:
|
|
|
|
- name: Stop Gitea for Backup
|
|
|
|
community.docker.docker_compose:
|
|
|
|
project_src: /opt/gitea
|
|
|
|
state: present
|
|
|
|
stopped: true
|
2023-04-29 20:37:01 +02:00
|
|
|
notify:
|
|
|
|
- Ensure Gitea is running
|
2022-11-11 17:52:53 +01:00
|
|
|
|
2023-04-29 21:52:00 +02:00
|
|
|
- name: Clean up Gitea Directory before restoring Backup
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /opt/gitea
|
|
|
|
state: absent
|
|
|
|
|
2023-04-28 23:42:01 +02:00
|
|
|
- name: Restore Gitea Directory from Backup
|
|
|
|
ansible.builtin.copy:
|
2023-04-29 21:52:00 +02:00
|
|
|
src: "{{ backup.dest }}/"
|
|
|
|
dest: /opt/gitea
|
2023-04-28 23:42:01 +02:00
|
|
|
remote_src: true
|
2023-04-29 21:52:00 +02:00
|
|
|
mode: preserve
|
2023-04-29 20:37:01 +02:00
|
|
|
notify:
|
|
|
|
- Check Gitea HTTP Response
|