def install_python_apt(module): if not module.check_mode: apt_get_path = module.get_bin_path('apt-get') if apt_get_path: rc, so, se = module.run_command([apt_get_path, 'update']) if rc != 0: module.fail_json( msg="Failed to auto-install python-apt. Error was: '%s'" % se.strip()) rc, so, se = module.run_command( [apt_get_path, 'install', 'python-apt', '-y', '-q']) if rc == 0: global apt, apt_pkg, aptsources_distro, distro, HAVE_PYTHON_APT import apt 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()) else: module.fail_json(msg="python-apt must be installed to use check mode")
def __init__(self, argv): self.parser = optparse.OptionParser(version=__VERSION__, description=__DESC__) self.filters = [] self._init_argv(argv) self.dist = distro.get_distro() self.sourceslist = sourceslist.SourcesList() self.dist.get_sources(self.sourceslist) if self.opts.etcroot: self.dist.sourceslist.refresh(self.opts.etcroot)
def install_python_apt(module): if not module.check_mode: apt_get_path = module.get_bin_path('apt-get') if 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: global apt, apt_pkg, aptsources_distro, distro, HAVE_PYTHON_APT import apt 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())
def get_repo_mirror_from_apt(self): """ This tries to determine the apt mirror/archive to use (when processing repos) if the host machine is Debian or Ubuntu. :return: False if the try fails or otherwise the mirrors. """ try: sources = sourceslist.SourcesList() release = debdistro.get_distro() release.get_sources(sources) mirrors = release.get_server_list() for mirror in mirrors: if mirror[2]: return mirror[1] except: return False
def get_repo_mirror_from_apt(self): """ This tries to determine the apt mirror/archive to use (when processing repos) if the host machine is Debian or Ubuntu. """ try: sources = sourceslist.SourcesList() release = debdistro.get_distro() release.get_sources(sources) mirrors = release.get_server_list() for mirror in mirrors: if mirror[2]: mirror = mirror[1] break except: return False return mirror
def get_repo_mirror_from_apt(self): """ This tries to determine the apt mirror/archive to use (when processing repos) if the host machine is Debian or Ubuntu. """ try: sources = sourceslist.SourcesList() release = distro.get_distro() release.get_sources(sources) mirrors = release.get_server_list() for mirror in mirrors: if mirror[2] == True: mirror = mirror[1] break except: return False return mirror
def install_python_apt(module): if not module.check_mode: apt_get_path = module.get_bin_path('apt-get') if apt_get_path: rc, so, se = module.run_command([apt_get_path, 'update']) if rc != 0: module.fail_json(msg="Failed to auto-install %s. Error was: '%s'" % (PYTHON_APT, se.strip())) rc, so, se = module.run_command([apt_get_path, 'install', PYTHON_APT, '-y', '-q']) if rc == 0: global apt, apt_pkg, aptsources_distro, distro, HAVE_PYTHON_APT import apt 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 %s. Error was: '%s'" % (PYTHON_APT, se.strip())) else: module.fail_json(msg="%s must be installed to use check mode" % PYTHON_APT)
repo: 'ppa:nginx/stable' codename: trusty ''' import glob import json import os import re import sys import tempfile try: import apt import apt_pkg import aptsources.distro as aptsources_distro distro = aptsources_distro.get_distro() HAVE_PYTHON_APT = True except ImportError: distro = None HAVE_PYTHON_APT = False from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native from ansible.module_utils.urls import fetch_url if sys.version_info[0] < 3: PYTHON_APT = 'python-apt' else: PYTHON_APT = 'python3-apt'
# On Ubuntu target: add nginx stable repository from PPA and install its signing key. # On Debian target: adding PPA is not available, so it will fail immediately. apt_repository: repo='ppa:nginx/stable' ''' import glob import os import re import tempfile try: import apt import apt_pkg import aptsources.distro as aptsources_distro distro = aptsources_distro.get_distro() HAVE_PYTHON_APT = True except ImportError: distro = None HAVE_PYTHON_APT = False VALID_SOURCE_TYPES = ('deb', 'deb-src') def install_python_apt(module): if not module.check_mode: apt_get_path = module.get_bin_path('apt-get') if 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: