refactor 2/2: ensureparentdir > ensuredir
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
galaxy_info:
|
||||
author: kevinnlsamuel
|
||||
description: sayin hello
|
||||
dependencies:
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
||||
@@ -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