Merge pull request #8292 from jimi-c/issue_7863_deb_with_items
Allow deb package installation via with_items
This commit is contained in:
commit
4a8e068855
1 changed files with 46 additions and 35 deletions
|
@ -291,50 +291,61 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
|
||||||
else:
|
else:
|
||||||
return (True, dict(changed=False))
|
return (True, dict(changed=False))
|
||||||
|
|
||||||
def install_deb(m, debfile, cache, force, install_recommends, dpkg_options):
|
def install_deb(m, debs, cache, force, install_recommends, dpkg_options):
|
||||||
changed=False
|
changed=False
|
||||||
pkg = apt.debfile.DebPackage(debfile)
|
deps_to_install = []
|
||||||
|
pkgs_to_install = []
|
||||||
|
for deb_file in debs.split(','):
|
||||||
|
pkg = apt.debfile.DebPackage(deb_file)
|
||||||
|
|
||||||
# Check if it's already installed
|
# Check if it's already installed
|
||||||
if pkg.compare_to_version_in_cache() == pkg.VERSION_SAME:
|
if pkg.compare_to_version_in_cache() == pkg.VERSION_SAME:
|
||||||
m.exit_json(changed=False)
|
continue
|
||||||
|
# Check if package is installable
|
||||||
|
if not pkg.check():
|
||||||
|
m.fail_json(msg=pkg._failure_string)
|
||||||
|
|
||||||
# Check if package is installable
|
# add any missing deps to the list of deps we need
|
||||||
if not pkg.check():
|
# to install so they're all done in one shot
|
||||||
m.fail_json(msg=pkg._failure_string)
|
deps_to_install.extend(pkg.missing_deps)
|
||||||
|
|
||||||
(success, retvals) = install(m=m, pkgspec=pkg.missing_deps,
|
# and add this deb to the list of packages to install
|
||||||
cache=cache,
|
pkgs_to_install.append(deb_file)
|
||||||
install_recommends=install_recommends,
|
|
||||||
dpkg_options=expand_dpkg_options(dpkg_options))
|
|
||||||
if not success:
|
|
||||||
m.fail_json(**retvals)
|
|
||||||
changed = retvals['changed']
|
|
||||||
|
|
||||||
|
# install the deps through apt
|
||||||
|
retvals = {}
|
||||||
|
if len(deps_to_install) > 0:
|
||||||
|
(success, retvals) = install(m=m, pkgspec=deps_to_install, cache=cache,
|
||||||
|
install_recommends=install_recommends,
|
||||||
|
dpkg_options=expand_dpkg_options(dpkg_options))
|
||||||
|
if not success:
|
||||||
|
m.fail_json(**retvals)
|
||||||
|
changed = retvals.get('changed', False)
|
||||||
|
|
||||||
options = ' '.join(["--%s"% x for x in dpkg_options.split(",")])
|
if len(pkgs_to_install) > 0:
|
||||||
|
options = ' '.join(["--%s"% x for x in dpkg_options.split(",")])
|
||||||
|
if m.check_mode:
|
||||||
|
options += " --simulate"
|
||||||
|
if force:
|
||||||
|
options += " --force-yes"
|
||||||
|
|
||||||
if m.check_mode:
|
cmd = "dpkg %s -i %s" % (options, " ".join(pkgs_to_install))
|
||||||
options += " --simulate"
|
rc, out, err = m.run_command(cmd)
|
||||||
if force:
|
if "stdout" in retvals:
|
||||||
options += " --force-yes"
|
stdout = retvals["stdout"] + out
|
||||||
|
else:
|
||||||
|
stdout = out
|
||||||
|
if "stderr" in retvals:
|
||||||
|
stderr = retvals["stderr"] + err
|
||||||
|
else:
|
||||||
|
stderr = err
|
||||||
|
|
||||||
|
if rc == 0:
|
||||||
cmd = "dpkg %s -i %s" % (options, debfile)
|
m.exit_json(changed=True, stdout=stdout, stderr=stderr)
|
||||||
rc, out, err = m.run_command(cmd)
|
else:
|
||||||
|
m.fail_json(msg="%s failed" % cmd, stdout=stdout, stderr=stderr)
|
||||||
if "stdout" in retvals:
|
|
||||||
stdout = retvals["stdout"] + out
|
|
||||||
else:
|
else:
|
||||||
stdout = out
|
m.exit_json(changed=changed, stdout=retvals.get('stdout',''), stderr=retvals.get('stderr',''))
|
||||||
if "stderr" in retvals:
|
|
||||||
stderr = retvals["stderr"] + err
|
|
||||||
else:
|
|
||||||
stderr = err
|
|
||||||
if rc == 0:
|
|
||||||
m.exit_json(changed=True, stdout=stdout, stderr=stderr)
|
|
||||||
else:
|
|
||||||
m.fail_json(msg="%s failed" % cmd, stdout=stdout, stderr=stderr)
|
|
||||||
|
|
||||||
def remove(m, pkgspec, cache, purge=False,
|
def remove(m, pkgspec, cache, purge=False,
|
||||||
dpkg_options=expand_dpkg_options(DPKG_OPTIONS)):
|
dpkg_options=expand_dpkg_options(DPKG_OPTIONS)):
|
||||||
|
|
Loading…
Reference in a new issue