mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-16 13:51:09 +00:00
Removing an non-existing directory complains (#19014)
The following playbook:
```yaml
- hosts: localhost
tasks:
- file:
path: /tmp/non-existing-foo-bar
state: absent
recurse: yes
```
causes this error:
```
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "recurse option requires state to be 'directory'", "path": "/tmp/non-existing-foo-bar", "state": "absent"}
```
The included fix ensures that when recurse is added, we no longer assume
it is a file, but accept that it is a directory.
This commit is contained in:
@@ -201,6 +201,7 @@ def main():
|
||||
|
||||
params = module.params
|
||||
state = params['state']
|
||||
recurse = params['recurse']
|
||||
force = params['force']
|
||||
diff_peek = params['diff_peek']
|
||||
src = params['src']
|
||||
@@ -231,6 +232,8 @@ def main():
|
||||
if state is None:
|
||||
if prev_state != 'absent':
|
||||
state = prev_state
|
||||
elif recurse:
|
||||
state = 'directory'
|
||||
else:
|
||||
state = 'file'
|
||||
|
||||
@@ -257,7 +260,6 @@ def main():
|
||||
b_path = to_bytes(path, errors='surrogate_or_strict')
|
||||
|
||||
# make sure the target path is a directory when we're doing a recursive operation
|
||||
recurse = params['recurse']
|
||||
if recurse and state != 'directory':
|
||||
module.fail_json(path=path, msg="recurse option requires state to be 'directory'")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user