Merge experimental nach main #3

Merged
sporq merged 16 commits from experimental into main 2023-05-01 18:37:47 +02:00
6 changed files with 104 additions and 76 deletions

View File

@ -1,6 +0,0 @@
# In den hier aufgelisteten Dateien sollen die dahinter stehenden
# Warnungen und Fehler von ansible-lint ignoriert werden.
tasks/main.yaml no-handler # Der Restart / Recreate Gitea Task ist gut dort, wo er ist
tasks/start.yaml name[template] # Es braucht zwei Templates, um den FQDN zusammenzusetzen.

30
handlers/backup.yaml Normal file
View File

@ -0,0 +1,30 @@
- name: Get stats of docker-compose.yaml
ansible.builtin.stat:
path: /opt/gitea/docker-compose.yaml
register: docker_compose_stat
listen:
- Backup Gitea
- name: Stop Gitea for Backup
community.docker.docker_compose:
project_src: /opt/gitea
state: present
stopped: true
register: docker_compose
listen:
- Backup Gitea
notify:
- Ensure Gitea is running
when: docker_compose_stat.stat.exists is defined and docker_compose_stat.stat.exists
- name: Backup Gitea Directory
community.general.archive:
path: /opt/gitea/
dest: "/var/backups/gitea-{{ gitea.hostname }}.{{ gitea.domain }}@{{ lookup('pipe', 'date --utc --iso-8601=seconds') }}.tar.gz"
force_archive: true
format: gz
owner: root
mode: "400"
listen:
- Backup Gitea
register: backup

32
handlers/main.yaml Normal file
View File

@ -0,0 +1,32 @@
- name: Import Backup Handler
ansible.builtin.import_tasks:
file: backup.yaml
- name: Ensure Gitea is restarted
community.docker.docker_compose:
project_src: /opt/gitea
restarted: true
register: docker_compose
- name: Ensure Gitea is running
community.docker.docker_compose:
project_src: /opt/gitea
register: docker_compose
- name: Get Gitea HTTP Response
ansible.builtin.uri:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}"
register: gitea_http_response
failed_when: 400 <= gitea_http_response.status < 500
- name: Wait until Gitea is up
ansible.builtin.uri:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}"
register: gitea_http_response
until: gitea_http_response.status == 200
retries: 30
delay: 2
- name: Output Docker Compose State
ansible.builtin.debug:
var: docker_compose

View File

@ -39,64 +39,48 @@
enabled: true
state: started
- name: Backup Files
block:
- name: Stop Gitea for Backup
community.docker.docker_compose:
project_src: /opt/gitea
state: present
stopped: true
- 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
notify:
- Backup Gitea
- name: Backup Gitea Directory
ansible.builtin.copy:
src: /opt/gitea/
dest: "/opt/gitea.backup@{{ lookup('pipe', 'date --utc --iso-8601=seconds') }}"
mode: "700"
remote_src: true
directory_mode: true
register: backup
- 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: Apply Changes
block:
- name: Upload Environment File
ansible.builtin.template:
src: environment.env.j2
dest: "/opt/gitea/environment.env"
owner: root
mode: "600"
register: gitea_env
- name: Execute Handlers before changing configfiles
ansible.builtin.meta: flush_handlers
- name: Upload docker-compose.yaml
ansible.builtin.template:
src: docker-compose.yaml.j2
dest: /opt/gitea/docker-compose.yaml
owner: root
mode: "600"
validate: /usr/bin/docker compose -f %s config -q
- name: Upload Environment File
ansible.builtin.template:
src: environment.env.j2
dest: "/opt/gitea/environment.env"
owner: root
mode: "600"
notify:
- Ensure Gitea is restarted
- Wait until Gitea is up
- name: Start Gitea and try reaching it
ansible.builtin.include_tasks:
file: start.yaml
rescue:
- name: Stop Gitea for Backup
community.docker.docker_compose:
project_src: /opt/gitea
state: present
stopped: true
- name: Restore Gitea Directory from Backup
ansible.builtin.copy:
src: "{{ backup.dest }}"
dest: "{{ backup.src }}"
remote_src: true
mode: "700"
- name: Start Gitea and try reaching it
ansible.builtin.include_tasks:
file: start.yaml
always:
- name: Output Docker Compose State
ansible.builtin.debug:
var: docker_compose
- 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
- Ensure Gitea is restarted
- Wait until Gitea is up

View File

@ -1,12 +0,0 @@
- name: Start Gitea
community.docker.docker_compose:
project_src: /opt/gitea
register: docker_compose
- 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

View File

@ -93,7 +93,7 @@ GITEA__service__ENABLE_NOTIFY_MAIL={{ gitea_vars.service.enable_notify_mail }}
GITEA__service__DEFAULT_KEEP_EMAIL_PRIVATE={{ gitea_vars.service.default_keep_email_private }}
{% endif %}
{% if 'default_allow_create_organization' in gitea_vars['service'] %}
GITEA__service__DEFAULT_ALLOW_CREATE_ORGANIZATION ={{ gitea_vars.service.default_allow_create_organization }}
GITEA__service__DEFAULT_ALLOW_CREATE_ORGANIZATION={{ gitea_vars.service.default_allow_create_organization }}
{% endif %}
{% if 'default_enable_timetracking' in gitea_vars['service'] %}
GITEA__service__DEFAULT_ENABLE_TIMETRACKING={{ gitea_vars.service.default_enable_timetracking }}