refactor 2/2: ensureparentdir > ensuredir
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
- name: check if dir exists
|
||||
register: stat_output
|
||||
ansible.builtin.stat:
|
||||
path: "{{ path }}"
|
||||
|
||||
- name: create dir if not exists
|
||||
when: not stat_output.stat.exists
|
||||
ansible.builtin.file:
|
||||
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 }}"
|
||||
no_log: true
|
||||
ansible.builtin.copy:
|
||||
src: "{{ path }}"
|
||||
dest: "{{ path }}.old"
|
||||
- name: "delete existing {{ path }}"
|
||||
no_log: true
|
||||
ansible.builtin.file:
|
||||
path: "{{ path }}"
|
||||
state: absent
|
||||
- name: "create {{ path }}"
|
||||
ansible.builtin.file:
|
||||
path: "{{ path }}"
|
||||
state: directory
|
||||
Reference in New Issue
Block a user