From a6575722402bfc879dfe3b81bbf7aa09b9a78598 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 27 Jan 2017 23:58:31 +0100 Subject: [PATCH] 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. --- lib/ansible/modules/files/file.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/files/file.py b/lib/ansible/modules/files/file.py index ac7790543c..ce722432be 100644 --- a/lib/ansible/modules/files/file.py +++ b/lib/ansible/modules/files/file.py @@ -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'")