mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Update file.py's initial_diff() to list existing when state: absent (#56353)
This commit is contained in:
parent
fba67bbe53
commit
91d326cb68
3 changed files with 38 additions and 2 deletions
|
@ -367,6 +367,21 @@ def initial_diff(path, state, prev_state):
|
|||
if prev_state != state:
|
||||
diff['before']['state'] = prev_state
|
||||
diff['after']['state'] = state
|
||||
if state == 'absent':
|
||||
walklist = {
|
||||
'directories': [],
|
||||
'files': [],
|
||||
}
|
||||
for base_path, sub_folders, files in os.walk(path):
|
||||
for folder in sub_folders:
|
||||
folderpath = os.path.join(base_path, folder)
|
||||
walklist['directories'].append(folderpath)
|
||||
|
||||
for filename in files:
|
||||
filepath = os.path.join(base_path, filename)
|
||||
walklist['files'].append(filepath)
|
||||
|
||||
diff['before']['path_content'] = walklist
|
||||
|
||||
return diff
|
||||
|
||||
|
@ -481,6 +496,8 @@ def ensure_absent(path):
|
|||
result = {}
|
||||
|
||||
if prev_state != 'absent':
|
||||
diff = initial_diff(path, 'absent', prev_state)
|
||||
|
||||
if not module.check_mode:
|
||||
if prev_state == 'directory':
|
||||
try:
|
||||
|
@ -495,7 +512,6 @@ def ensure_absent(path):
|
|||
raise AnsibleModuleError(results={'msg': "unlinking failed: %s " % to_native(e),
|
||||
'path': path})
|
||||
|
||||
diff = initial_diff(path, 'absent', prev_state)
|
||||
result.update({'path': path, 'changed': True, 'diff': diff, 'state': 'absent'})
|
||||
else:
|
||||
result.update({'path': path, 'changed': False, 'state': 'absent'})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue