From 829e8225f662ac492b324b666f97dda95ba9b904 Mon Sep 17 00:00:00 2001 From: kevinnls Date: Tue, 15 Sep 2026 21:53:54 +0530 Subject: [PATCH] refactor 1/2 ensureparentdir > ensuredir --- roles/ensureparentdir/tasks/main.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/roles/ensureparentdir/tasks/main.yml b/roles/ensureparentdir/tasks/main.yml index 8c261ab..043e424 100644 --- a/roles/ensureparentdir/tasks/main.yml +++ b/roles/ensureparentdir/tasks/main.yml @@ -1,29 +1,28 @@ -- name: check if parent dir exists +- name: check if dir exists register: stat_output ansible.builtin.stat: - path: "{{ path | dirname }}" + path: "{{ path }}" - name: create dir if not exists when: not stat_output.stat.exists ansible.builtin.file: - path: "{{ path | dirname }}" + path: "{{ path }}" 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 }}" + - name: "backup existing {{ path }}" no_log: true ansible.builtin.copy: - src: "{{ path | dirname }}" - dest: "{{ path | dirname }}.old" - - name: "delete existing {{ path | dirname }}" + src: "{{ path }}" + dest: "{{ path }}.old" + - name: "delete existing {{ path }}" no_log: true ansible.builtin.file: - path: "{{ path | dirname }}" + path: "{{ path }}" state: absent - - name: "create {{ path | dirname }}" - no_log: true + - name: "create {{ path }}" ansible.builtin.file: - path: "{{ path | dirname }}" + path: "{{ path }}" state: directory