Merge pull request 'Merge experimental nach main' (#3) from experimental into main
All checks were successful
ansible-lint / Ansible Lint (push) Successful in 13s

Reviewed-on: #3
This commit is contained in:
Marius Alwan Meyer 2023-05-01 16:37:47 +00:00
commit 32ac3f842a
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 enabled: true
state: started state: started
- name: Backup Files - name: Check if environment.env will get changed
block: ansible.builtin.template:
- name: Stop Gitea for Backup src: environment.env.j2
community.docker.docker_compose: dest: "/opt/gitea/environment.env"
project_src: /opt/gitea owner: root
state: present mode: "600"
stopped: true register: env_diff
check_mode: true
notify:
- Backup Gitea
- name: Backup Gitea Directory - name: Check if docker-compose.yaml will get changed
ansible.builtin.copy: ansible.builtin.template:
src: /opt/gitea/ src: docker-compose.yaml.j2
dest: "/opt/gitea.backup@{{ lookup('pipe', 'date --utc --iso-8601=seconds') }}" dest: /opt/gitea/docker-compose.yaml
mode: "700" owner: root
remote_src: true mode: "600"
directory_mode: true register: docker_compose_diff
register: backup check_mode: true
notify:
- Backup Gitea
- name: Apply Changes - name: Execute Handlers before changing configfiles
block: ansible.builtin.meta: flush_handlers
- name: Upload Environment File
ansible.builtin.template:
src: environment.env.j2
dest: "/opt/gitea/environment.env"
owner: root
mode: "600"
register: gitea_env
- name: Upload docker-compose.yaml - name: Upload Environment File
ansible.builtin.template: ansible.builtin.template:
src: docker-compose.yaml.j2 src: environment.env.j2
dest: /opt/gitea/docker-compose.yaml dest: "/opt/gitea/environment.env"
owner: root owner: root
mode: "600" mode: "600"
validate: /usr/bin/docker compose -f %s config -q notify:
- Ensure Gitea is restarted
- Wait until Gitea is up
- name: Start Gitea and try reaching it - name: Upload docker-compose.yaml
ansible.builtin.include_tasks: ansible.builtin.template:
file: start.yaml src: docker-compose.yaml.j2
dest: /opt/gitea/docker-compose.yaml
rescue: owner: root
- name: Stop Gitea for Backup mode: "600"
community.docker.docker_compose: notify:
project_src: /opt/gitea - Output Docker Compose State
state: present - Ensure Gitea is restarted
stopped: true - Wait until Gitea is up
- 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

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 }} GITEA__service__DEFAULT_KEEP_EMAIL_PRIVATE={{ gitea_vars.service.default_keep_email_private }}
{% endif %} {% endif %}
{% if 'default_allow_create_organization' in gitea_vars['service'] %} {% 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 %} {% endif %}
{% if 'default_enable_timetracking' in gitea_vars['service'] %} {% if 'default_enable_timetracking' in gitea_vars['service'] %}
GITEA__service__DEFAULT_ENABLE_TIMETRACKING={{ gitea_vars.service.default_enable_timetracking }} GITEA__service__DEFAULT_ENABLE_TIMETRACKING={{ gitea_vars.service.default_enable_timetracking }}