From 1ae018ce941fa5535fe1032d81284b469d64862d Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 20 Aug 2012 18:39:37 -0400 Subject: [PATCH] Adds a thirsty=yes|no to the get_url module, such that if downloading a large file from the internet you can decide whether to download it every time or not -- will replace only on change, or decide to not download. The default is thirsty=no which will not download every time by default. --- CHANGELOG.md | 1 + library/get_url | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdbba0679e..f49aa439ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Module changes: * new module boilerplate code to check for mutually required arguments, arguments required together, exclusive args * add pattern= as a paramter to the service module (for init scripts that don't do status, or do poor status) * various fixes to mysql & postresql modules +* added a thirsty= option (boolean, default no) to the get_url module to decide to download the file every time or not Core changes: diff --git a/library/get_url b/library/get_url index 592110afa9..f557b29ab9 100755 --- a/library/get_url +++ b/library/get_url @@ -136,11 +136,20 @@ def main(): argument_spec = dict( url = dict(required=True), dest = dict(required=True), + thirsty = dict(default='no', choices=BOOLEANS) ) ) url = module.params['url'] dest = os.path.expanduser(module.params['dest']) + thirsty = module.boolean(module.params['thirsty']) + + if not thirsty: + if os.path.exists(dest): + module.exit_json(msg="file already exists", changed=False) + if os.path.isdir(dest): + module.fail_json(msg="non-thirsty mode needs a filename for a destination, not a directory") + # download to tmpsrc tmpsrc, info = url_get(module, url, dest)