mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02: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:
parent
971783a7fd
commit
a657572240
1 changed files with 3 additions and 1 deletions
|
@ -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'")
|
||||
|
||||
|
|
Loading…
Reference in a new issue