ansible-role-gitea/tasks/main.yaml

119 lines
2.9 KiB
YAML
Raw Permalink Normal View History

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
- name: Create Gitea
2023-04-29 00:30:47 +02:00
ansible.builtin.file:
path: "/opt/gitea"
state: directory
owner: root
2023-04-29 00:30:47 +02:00
mode: "755"
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
- name: Backup Files
block:
- name: Stop Gitea for Backup
community.docker.docker_compose:
project_src: /opt/gitea
state: present
stopped: true
- name: Backup Gitea Directory
ansible.builtin.copy:
src: /opt/gitea
dest: "/opt/gitea.backup@{{ ansible_date_time.iso8601 }}"
2023-04-29 00:30:47 +02:00
mode: "700"
remote_src: true
directory_mode: true
register: backup
- name: Apply Changes
block:
- name: Upload Environment File
ansible.builtin.template:
src: environment.env.j2
dest: "/opt/gitea/environment.env"
owner: root
2023-04-29 00:30:47 +02:00
mode: "600"
register: gitea_env
- name: Upload docker-compose.yaml
ansible.builtin.template:
src: docker-compose.yaml.j2
dest: /opt/gitea/docker-compose.yaml
owner: root
2023-04-29 00:30:47 +02:00
mode: "600"
register: gitea_container
- name: Create / Recreate Gitea
community.docker.docker_compose:
project_src: /opt/gitea
state: present
restarted: true
when: gitea_env.changed or gitea_container.changed
- name: Check if {{ gitea.hostname }}.{{ gitea.domain }} is available and returning status 200
ansible.builtin.uri:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}"
register: _result
until: _result.status == 200
retries: 30
delay: 2
rescue:
- name: Stop Gitea for Backup
community.docker.docker_compose:
project_src: /opt/gitea
state: present
stopped: true
2022-11-11 17:52:53 +01:00
- name: Restore Gitea Directory from Backup
ansible.builtin.copy:
src: "{{ backup.dest }}"
dest: "{{ backup.src }}"
remote_src: true
2023-04-29 00:30:47 +02:00
mode: "700"
- name: Create / Recreate Gitea
community.docker.docker_compose:
project_src: /opt/gitea
state: present
restarted: true
always:
- name: Check if {{ gitea.hostname }}.{{ gitea.domain }} is available and returning status 200
ansible.builtin.uri:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}"
register: _result
until: _result.status == 200
retries: 30
delay: 2