Nutze Handler für ein simpleres Playbook

This commit is contained in:
Marius Alwan Meyer 2023-04-29 18:37:01 +00:00
parent d0258a3fc2
commit c391a07485
2 changed files with 55 additions and 46 deletions

View File

@ -1,12 +1,16 @@
- name: Start Gitea - name: Ensure Gitea is running
community.docker.docker_compose: community.docker.docker_compose:
project_src: /opt/gitea project_src: /opt/gitea
register: docker_compose
- name: Check if {{ gitea.hostname }}.{{ gitea.domain }} is available and returning status 200 - name: Check Gitea HTTP Response
ansible.builtin.uri: ansible.builtin.uri:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}" url: "https://{{ gitea.hostname }}.{{ gitea.domain }}"
register: _result register: _result
until: _result.status == 200 until: _result.status == 200
retries: 30 retries: 30
delay: 2 delay: 2
- name: Output Docker Compose State
ansible.builtin.debug:
var: docker_compose
when: gitea_docker_compose.changed

View File

@ -39,13 +39,13 @@
enabled: true enabled: true
state: started state: started
- name: Backup Files
block:
- name: Stop Gitea for Backup - name: Stop Gitea for Backup
community.docker.docker_compose: community.docker.docker_compose:
project_src: /opt/gitea project_src: /opt/gitea
state: present state: present
stopped: true stopped: true
notify:
- Ensure Gitea is running
- name: Backup Gitea Directory - name: Backup Gitea Directory
ansible.builtin.copy: ansible.builtin.copy:
@ -56,15 +56,12 @@
directory_mode: true directory_mode: true
register: backup register: backup
- name: Apply Changes
block:
- name: Upload Environment File - name: Upload Environment File
ansible.builtin.template: ansible.builtin.template:
src: environment.env.j2 src: environment.env.j2
dest: "/opt/gitea/environment.env" dest: "/opt/gitea/environment.env"
owner: root owner: root
mode: "600" mode: "600"
register: gitea_env
- name: Upload docker-compose.yaml - name: Upload docker-compose.yaml
ansible.builtin.template: ansible.builtin.template:
@ -73,10 +70,23 @@
owner: root owner: root
mode: "600" mode: "600"
validate: /usr/bin/docker compose -f %s config -q validate: /usr/bin/docker compose -f %s config -q
notify:
- Output Docker Compose State
- name: Start Gitea and try reaching it - name: Try to reach Gitea
ansible.builtin.include_tasks: block:
file: start.yaml
- name: Start Gitea
community.docker.docker_compose:
project_src: /opt/gitea
- 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: rescue:
- name: Stop Gitea for Backup - name: Stop Gitea for Backup
@ -84,6 +94,8 @@
project_src: /opt/gitea project_src: /opt/gitea
state: present state: present
stopped: true stopped: true
notify:
- Ensure Gitea is running
- name: Restore Gitea Directory from Backup - name: Restore Gitea Directory from Backup
ansible.builtin.copy: ansible.builtin.copy:
@ -91,12 +103,5 @@
dest: "{{ backup.src }}" dest: "{{ backup.src }}"
remote_src: true remote_src: true
mode: "700" mode: "700"
notify:
- name: Start Gitea and try reaching it - Check Gitea HTTP Response
ansible.builtin.include_tasks:
file: start.yaml
always:
- name: Output Docker Compose State
ansible.builtin.debug:
var: docker_compose