Repository: ansible/ansible

Issue:
get_url should check if directory exists
##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
ansible/get_url

##### ANSIBLE VERSION
Commit 0765ceb66dfad116ec0519a0f9272158da6600d0 (current master)

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### SUMMARY
Ansible should report if the current directory doesn't exist.

It already checks if the file exists, but not the directory.

##### STEPS TO REPRODUCE
Provide the path to a non-existing directory

##### EXPECTED RESULTS
"Destination %s does not exist"

##### ACTUAL RESULTS
"Destination %s not writable"

##### Relevant LOC

https://github.com/ansible/ansible/blob/0765ceb66dfad116ec0519a0f9272158da6600d0/lib/ansible/modules/net_tools/basics/get_url.py#L519

get_url should check if directory exists
##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
ansible/get_url

##### ANSIBLE VERSION
Commit 0765ceb66dfad116ec0519a0f9272158da6600d0 (current master)

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### SUMMARY
Ansible should report if the current directory doesn't exist.

It already checks if the file exists, but not the directory.

##### STEPS TO REPRODUCE
Provide the path to a non-existing directory

##### EXPECTED RESULTS
"Destination %s does not exist"

##### ACTUAL RESULTS
"Destination %s not writable"

##### Relevant LOC

https://github.com/ansible/ansible/blob/0765ceb66dfad116ec0519a0f9272158da6600d0/lib/ansible/modules/net_tools/basics/get_url.py#L519



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/net_tools/basics/get_url.py b/lib/ansible/modules/net_tools/basics/get_url.py
--- a/lib/ansible/modules/net_tools/basics/get_url.py
+++ b/lib/ansible/modules/net_tools/basics/get_url.py
@@ -502,7 +502,7 @@ def main():
         module.fail_json(msg="Request failed", status_code=info['status'], response=info['msg'])
     if not os.access(tmpsrc, os.R_OK):
         os.remove(tmpsrc)
-        module.fail_json(msg="Source %s not readable" % (tmpsrc))
+        module.fail_json(msg="Source %s is not readable" % (tmpsrc))
     checksum_src = module.sha1(tmpsrc)
 
     # check if there is no dest file
@@ -510,15 +510,18 @@ def main():
         # raise an error if copy has no permission on dest
         if not os.access(dest, os.W_OK):
             os.remove(tmpsrc)
-            module.fail_json(msg="Destination %s not writable" % (dest))
+            module.fail_json(msg="Destination %s is not writable" % (dest))
         if not os.access(dest, os.R_OK):
             os.remove(tmpsrc)
-            module.fail_json(msg="Destination %s not readable" % (dest))
+            module.fail_json(msg="Destination %s is not readable" % (dest))
         checksum_dest = module.sha1(dest)
     else:
+        if not os.path.exists(os.path.dirname(dest)):
+            os.remove(tmpsrc)
+            module.fail_json(msg="Destination %s does not exist" % (os.path.dirname(dest)))
         if not os.access(os.path.dirname(dest), os.W_OK):
             os.remove(tmpsrc)
-            module.fail_json(msg="Destination %s not writable" % (os.path.dirname(dest)))
+            module.fail_json(msg="Destination %s is not writable" % (os.path.dirname(dest)))
 
     backup_file = None
     if checksum_src != checksum_dest:


Test patch: