refactor 1/2 ensureparentdir > ensuredir
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user