29 lines
745 B
YAML
29 lines
745 B
YAML
- 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
|