|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = r'''
|
|
|
|
|
---
|
|
|
|
|
module: file
|
|
|
|
@ -539,16 +540,16 @@ def ensure_absent(path):
|
|
|
|
|
if '-a' in current_attributes:
|
|
|
|
|
# Attempt to remove the append-only attribute before deletion
|
|
|
|
|
try:
|
|
|
|
|
module.set_attributes_if_different(path, current_attributes, changed, diff, expand=False)
|
|
|
|
|
module.set_attributes_if_different(path, current_attributes, changed,
|
|
|
|
|
diff, expand=False)
|
|
|
|
|
changed = True # Mark as changed if attributes were modified
|
|
|
|
|
except Exception as e:
|
|
|
|
|
module.fail_json(msg="Failed to change attributes: %s" % to_native(e), path=to_native(b_path))
|
|
|
|
|
module.fail_json(msg="Failed to change attributes: %s" % to_native(e),
|
|
|
|
|
path=to_native(b_path))
|
|
|
|
|
try:
|
|
|
|
|
shutil.rmtree(b_path, ignore_errors=False)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
# raise AnsibleModuleError(results={'msg': "rmtree failed: %s" % to_native(e)})
|
|
|
|
|
raise AnsibleModuleError(results={'msg': "rmtree failed: %s" % to_native(e),
|
|
|
|
|
'details': "Attributes before removal: %s, Changed: %s" % (file_args.get('attributes', 'None'), changed)})
|
|
|
|
|
raise AnsibleModuleError(results={'msg': "rmtree failed: %s" % to_native(e)})
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
os.unlink(b_path)
|
|
|
|
|