# - name: Install Dependencies # apt: # pkg: # - apparmor # - docker.io # - python3-docker - name: Create git USER ansible.builtin.user: name: git register: git_user - name: Create Gitea ansible.builtin.file: path: "/opt/gitea" state: directory owner: root mode: "755" - name: Create Data Directory ansible.builtin.file: path: "/opt/gitea/data" state: directory owner: "{{ git_user.uid }}" group: "{{ git_user.group }}" mode: "700" - name: Create Config Directory ansible.builtin.file: path: "/opt/gitea/config" state: directory owner: "{{ git_user.uid }}" group: "{{ git_user.group }}" mode: "700" - name: Start Docker Daemon ansible.builtin.systemd: name: docker 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: 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: 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: 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 register: gitea_container - 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