From abe2daebb992ff9c83b562bafd100e238e326fef Mon Sep 17 00:00:00 2001 From: kevinnlsamuel Date: Tue, 15 Sep 2026 14:34:47 +0530 Subject: [PATCH] this is stupid --- roles/ensureparentdir/tasks/main.yml | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/roles/ensureparentdir/tasks/main.yml b/roles/ensureparentdir/tasks/main.yml index 25e8b98..8c261ab 100644 --- a/roles/ensureparentdir/tasks/main.yml +++ b/roles/ensureparentdir/tasks/main.yml @@ -1,5 +1,29 @@ - name: check if parent dir exists - debug: - msg: "{{ path }}" + register: stat_output + ansible.builtin.stat: + path: "{{ path | dirname }}" +- name: create dir if not exists + when: not stat_output.stat.exists + ansible.builtin.file: + path: "{{ path | dirname }}" + state: directory +- name: backup and create dir if not dir + when: stat_output.stat.exists and not stat_output.stat.isdir + block: + - name: "backup existing {{ path | dirname }}" + no_log: true + ansible.builtin.copy: + src: "{{ path | dirname }}" + dest: "{{ path | dirname }}.old" + - name: "delete existing {{ path | dirname }}" + no_log: true + ansible.builtin.file: + path: "{{ path | dirname }}" + state: absent + - name: "create {{ path | dirname }}" + no_log: true + ansible.builtin.file: + path: "{{ path | dirname }}" + state: directory