refactor 1/2 ensureparentdir > ensuredir

This commit is contained in:
2026-09-15 21:53:54 +05:30
parent e07b18b587
commit 829e8225f6
+10 -11
View File
@@ -1,29 +1,28 @@
- name: check if parent dir exists - name: check if dir exists
register: stat_output register: stat_output
ansible.builtin.stat: ansible.builtin.stat:
path: "{{ path | dirname }}" path: "{{ path }}"
- name: create dir if not exists - name: create dir if not exists
when: not stat_output.stat.exists when: not stat_output.stat.exists
ansible.builtin.file: ansible.builtin.file:
path: "{{ path | dirname }}" path: "{{ path }}"
state: directory state: directory
- name: backup and create dir if not dir - name: backup and create dir if not dir
when: stat_output.stat.exists and not stat_output.stat.isdir when: stat_output.stat.exists and not stat_output.stat.isdir
block: block:
- name: "backup existing {{ path | dirname }}" - name: "backup existing {{ path }}"
no_log: true no_log: true
ansible.builtin.copy: ansible.builtin.copy:
src: "{{ path | dirname }}" src: "{{ path }}"
dest: "{{ path | dirname }}.old" dest: "{{ path }}.old"
- name: "delete existing {{ path | dirname }}" - name: "delete existing {{ path }}"
no_log: true no_log: true
ansible.builtin.file: ansible.builtin.file:
path: "{{ path | dirname }}" path: "{{ path }}"
state: absent state: absent
- name: "create {{ path | dirname }}" - name: "create {{ path }}"
no_log: true
ansible.builtin.file: ansible.builtin.file:
path: "{{ path | dirname }}" path: "{{ path }}"
state: directory state: directory