From 2e14557b21065a4c3722954c765a0c41b52393a6 Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Sat, 8 Nov 2025 15:12:06 +0100 Subject: [PATCH] fix: Handle case where destination exists but is not a git repo - Check if destination directory exists separately from git repo check - Remove directory if it exists but is not a git repository - Prevents 'destination path already exists' error during clone --- .../ansible/playbooks/deploy-application-code.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/deployment/ansible/playbooks/deploy-application-code.yml b/deployment/ansible/playbooks/deploy-application-code.yml index 2e4b55a0..a5d40a82 100644 --- a/deployment/ansible/playbooks/deploy-application-code.yml +++ b/deployment/ansible/playbooks/deploy-application-code.yml @@ -44,6 +44,18 @@ path: "{{ application_code_dest }}/.git" register: git_repo_exists + - name: Check if destination directory exists + stat: + path: "{{ application_code_dest }}" + register: dest_dir_exists + + - name: Remove destination directory if it exists but is not a git repo + file: + path: "{{ application_code_dest }}" + state: absent + when: dest_dir_exists.stat.exists and not git_repo_exists.stat.exists + become: yes + - name: Clone repository (if not exists) ansible.builtin.git: repo: "{{ git_repo_url }}"