Add ability to download deb from url
if :// in deb, will try to download from url.
This commit is contained in:
parent
3abdfb1712
commit
44bde46097
1 changed files with 32 additions and 0 deletions
32
lib/ansible/modules/packaging/os/apt.py
Executable file → Normal file
32
lib/ansible/modules/packaging/os/apt.py
Executable file → Normal file
|
@ -92,6 +92,7 @@ options:
|
||||||
deb:
|
deb:
|
||||||
description:
|
description:
|
||||||
- Path to a .deb package on the remote machine.
|
- Path to a .deb package on the remote machine.
|
||||||
|
- If :// in the path, ansible will attempt to download deb before installing. (Version added 2.1)
|
||||||
required: false
|
required: false
|
||||||
version_added: "1.6"
|
version_added: "1.6"
|
||||||
autoremove:
|
autoremove:
|
||||||
|
@ -144,6 +145,9 @@ EXAMPLES = '''
|
||||||
|
|
||||||
# Install the build dependencies for package "foo"
|
# Install the build dependencies for package "foo"
|
||||||
- apt: pkg=foo state=build-dep
|
- apt: pkg=foo state=build-dep
|
||||||
|
|
||||||
|
# Install a .deb package from the internet.
|
||||||
|
- apt: deb=https://example.com/python-ppq_0.1-1_all.deb
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -555,6 +559,31 @@ def upgrade(m, mode="yes", force=False, default_release=None,
|
||||||
m.exit_json(changed=False, msg=out, stdout=out, stderr=err)
|
m.exit_json(changed=False, msg=out, stdout=out, stderr=err)
|
||||||
m.exit_json(changed=True, msg=out, stdout=out, stderr=err)
|
m.exit_json(changed=True, msg=out, stdout=out, stderr=err)
|
||||||
|
|
||||||
|
def download(module, deb):
|
||||||
|
tempdir = os.path.dirname(__file__)
|
||||||
|
package = os.path.join(tempdir, str(deb.rsplit('/', 1)[1]))
|
||||||
|
# When downloading a deb, how much of the deb to download before
|
||||||
|
# saving to a tempfile (64k)
|
||||||
|
BUFSIZE = 65536
|
||||||
|
|
||||||
|
try:
|
||||||
|
rsp, info = fetch_url(module, deb)
|
||||||
|
f = open(package, 'w')
|
||||||
|
# Read 1kb at a time to save on ram
|
||||||
|
while True:
|
||||||
|
data = rsp.read(BUFSIZE)
|
||||||
|
|
||||||
|
if data == "":
|
||||||
|
break # End of file, break while loop
|
||||||
|
|
||||||
|
f.write(data)
|
||||||
|
f.close()
|
||||||
|
deb = package
|
||||||
|
except Exception, e:
|
||||||
|
module.fail_json(msg="Failure downloading %s, %s" % (deb, e))
|
||||||
|
|
||||||
|
return deb
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
@ -667,6 +696,8 @@ def main():
|
||||||
if p['deb']:
|
if p['deb']:
|
||||||
if p['state'] != 'present':
|
if p['state'] != 'present':
|
||||||
module.fail_json(msg="deb only supports state=present")
|
module.fail_json(msg="deb only supports state=present")
|
||||||
|
if '://' in p['deb']:
|
||||||
|
p['deb'] = download(module, p['deb'])
|
||||||
install_deb(module, p['deb'], cache,
|
install_deb(module, p['deb'], cache,
|
||||||
install_recommends=install_recommends,
|
install_recommends=install_recommends,
|
||||||
force=force_yes, dpkg_options=p['dpkg_options'])
|
force=force_yes, dpkg_options=p['dpkg_options'])
|
||||||
|
@ -708,6 +739,7 @@ def main():
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import *
|
from ansible.module_utils.basic import *
|
||||||
|
from ansible.module_utils.urls import *
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue