mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Make sure distro variable is set if python-apt is installed
Fixes #7295
This commit is contained in:
parent
941af22d5d
commit
537494c2d6
1 changed files with 19 additions and 11 deletions
|
@ -83,10 +83,11 @@ import tempfile
|
||||||
try:
|
try:
|
||||||
import apt
|
import apt
|
||||||
import apt_pkg
|
import apt_pkg
|
||||||
import aptsources.distro
|
import aptsources.distro as aptsources_distro
|
||||||
distro = aptsources.distro.get_distro()
|
distro = aptsources_distro.get_distro()
|
||||||
HAVE_PYTHON_APT = True
|
HAVE_PYTHON_APT = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
distro = None
|
||||||
HAVE_PYTHON_APT = False
|
HAVE_PYTHON_APT = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,11 +98,16 @@ def install_python_apt(module):
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
apt_get_path = module.get_bin_path('apt-get')
|
apt_get_path = module.get_bin_path('apt-get')
|
||||||
if apt_get_path:
|
if apt_get_path:
|
||||||
rc, so, se = module.run_command('%s update && %s install python-apt -y -q' % (apt_get_path, apt_get_path))
|
rc, so, se = module.run_command('%s update && %s install python-apt -y -q' % (apt_get_path, apt_get_path), use_unsafe_shell=True)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
global apt, apt_pkg
|
global apt, apt_pkg, aptsources_distro, distro, HAVE_PYTHON_APT
|
||||||
import apt
|
import apt
|
||||||
import apt_pkg
|
import apt_pkg
|
||||||
|
import aptsources.distro as aptsources_distro
|
||||||
|
distro = aptsources_distro.get_distro()
|
||||||
|
HAVE_PYTHON_APT = True
|
||||||
|
else:
|
||||||
|
module.fail_json(msg="Failed to auto-install python-apt. Error was: '%s'" % se.strip())
|
||||||
|
|
||||||
class InvalidSource(Exception):
|
class InvalidSource(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -382,14 +388,16 @@ def main():
|
||||||
update_cache = module.params['update_cache']
|
update_cache = module.params['update_cache']
|
||||||
sourceslist = None
|
sourceslist = None
|
||||||
|
|
||||||
if isinstance(distro, aptsources.distro.UbuntuDistribution):
|
if HAVE_PYTHON_APT:
|
||||||
sourceslist = UbuntuSourcesList(module,
|
if isinstance(distro, aptsources_distro.UbuntuDistribution):
|
||||||
add_ppa_signing_keys_callback=get_add_ppa_signing_key_callback(module))
|
sourceslist = UbuntuSourcesList(module,
|
||||||
elif isinstance(distro, aptsources.distro.DebianDistribution) or \
|
add_ppa_signing_keys_callback=get_add_ppa_signing_key_callback(module))
|
||||||
isinstance(distro, aptsources.distro.Distribution):
|
elif HAVE_PYTHON_APT and \
|
||||||
sourceslist = SourcesList()
|
isinstance(distro, aptsources_distro.DebianDistribution) or isinstance(distro, aptsources_distro.Distribution):
|
||||||
|
sourceslist = SourcesList()
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='Module apt_repository supports only Debian and Ubuntu.')
|
module.fail_json(msg='Module apt_repository supports only Debian and Ubuntu. ' + \
|
||||||
|
'You may be seeing this because python-apt is not installed, but you requested that it not be auto-installed')
|
||||||
|
|
||||||
sources_before = sourceslist.dump()
|
sources_before = sourceslist.dump()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue