Added 'backup' parameter to get_url module
This commit is contained in:
parent
0930a44816
commit
49ec5a6a30
1 changed files with 21 additions and 2 deletions
|
@ -75,6 +75,13 @@ options:
|
||||||
choices: [ "yes", "no" ]
|
choices: [ "yes", "no" ]
|
||||||
default: "no"
|
default: "no"
|
||||||
aliases: [ "thirsty" ]
|
aliases: [ "thirsty" ]
|
||||||
|
backup:
|
||||||
|
description:
|
||||||
|
- Create a backup file including the timestamp information so you can get
|
||||||
|
the original file back if you somehow clobbered it incorrectly.
|
||||||
|
required: false
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
default: "no"
|
||||||
sha256sum:
|
sha256sum:
|
||||||
description:
|
description:
|
||||||
- If a SHA-256 checksum is passed to this parameter, the digest of the
|
- If a SHA-256 checksum is passed to this parameter, the digest of the
|
||||||
|
@ -251,6 +258,7 @@ def main():
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
url = dict(required=True),
|
url = dict(required=True),
|
||||||
dest = dict(required=True),
|
dest = dict(required=True),
|
||||||
|
backup = dict(default=False, type='bool'),
|
||||||
sha256sum = dict(default=''),
|
sha256sum = dict(default=''),
|
||||||
checksum = dict(default=''),
|
checksum = dict(default=''),
|
||||||
timeout = dict(required=False, type='int', default=10),
|
timeout = dict(required=False, type='int', default=10),
|
||||||
|
@ -266,6 +274,7 @@ def main():
|
||||||
|
|
||||||
url = module.params['url']
|
url = module.params['url']
|
||||||
dest = os.path.expanduser(module.params['dest'])
|
dest = os.path.expanduser(module.params['dest'])
|
||||||
|
backup = module.params['backup']
|
||||||
force = module.params['force']
|
force = module.params['force']
|
||||||
sha256sum = module.params['sha256sum']
|
sha256sum = module.params['sha256sum']
|
||||||
checksum = module.params['checksum']
|
checksum = module.params['checksum']
|
||||||
|
@ -366,8 +375,12 @@ def main():
|
||||||
os.remove(tmpsrc)
|
os.remove(tmpsrc)
|
||||||
module.fail_json( msg="Destination %s not writable" % (os.path.dirname(dest)))
|
module.fail_json( msg="Destination %s not writable" % (os.path.dirname(dest)))
|
||||||
|
|
||||||
|
backup_file = None
|
||||||
if checksum_src != checksum_dest:
|
if checksum_src != checksum_dest:
|
||||||
try:
|
try:
|
||||||
|
if backup:
|
||||||
|
if os.path.exists(dest):
|
||||||
|
backup_file = module.backup_local(dest)
|
||||||
shutil.copyfile(tmpsrc, dest)
|
shutil.copyfile(tmpsrc, dest)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
os.remove(tmpsrc)
|
os.remove(tmpsrc)
|
||||||
|
@ -397,9 +410,15 @@ def main():
|
||||||
except ValueError:
|
except ValueError:
|
||||||
md5sum = None
|
md5sum = None
|
||||||
|
|
||||||
|
res_args = dict(
|
||||||
|
url = url, dest = dest, src = tmpsrc, md5sum = md5sum, checksum_src = checksum_src,
|
||||||
|
checksum_dest = checksum_dest, changed = changed, msg = info.get('msg', '')
|
||||||
|
)
|
||||||
|
if backup_file:
|
||||||
|
res_args['backup_file'] = backup_file
|
||||||
|
|
||||||
# Mission complete
|
# Mission complete
|
||||||
module.exit_json(url=url, dest=dest, src=tmpsrc, md5sum=md5sum, checksum_src=checksum_src,
|
module.exit_json(**res_args)
|
||||||
checksum_dest=checksum_dest, changed=changed, msg=info.get('msg', ''))
|
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import *
|
from ansible.module_utils.basic import *
|
||||||
|
|
Loading…
Reference in a new issue