def get_distribution_codename(): ''' Return the code name for this Linux Distribution :rtype: NativeString or None :returns: A string representation of the distribution's codename or None if not a Linux distro ''' codename = None if platform.system() == 'Linux': # Until this gets merged and we update our bundled copy of distro: # https://github.com/nir0s/distro/pull/230 # Fixes Fedora 28+ not having a code name and Ubuntu Xenial Xerus needing to be "xenial" os_release_info = distro.os_release_info() codename = os_release_info.get('version_codename') if codename is None: codename = os_release_info.get('ubuntu_codename') if codename is None and distro.id() == 'ubuntu': lsb_release_info = distro.lsb_release_info() codename = lsb_release_info.get('codename') if codename is None: codename = distro.codename() if codename == u'': codename = None return codename
def __init__(self, module): """ Initialize all needed Variables """ self.module = module self.state = module.params.get("state") self.package_version = module.params.get("package_version") self.package_name = module.params.get("package_name") self.repository = module.params.get("repository") self.distribution = distro.id() self.version = distro.version() self.codename = distro.codename()
'/etc/os-release', '/etc/coreos/update.conf', '/etc/flatcar/update.conf', '/usr/lib/os-release', ] fcont = {} for f in filelist: if os.path.exists(f): s = os.path.getsize(f) if s > 0 and s < 10000: with open(f) as fh: fcont[f] = fh.read() dist = (distro.id(), distro.version(), distro.codename()) facts = [ 'distribution', 'distribution_version', 'distribution_release', 'distribution_major_version', 'os_family' ] try: b_ansible_out = subprocess.check_output( ['ansible', 'localhost', '-m', 'setup']) except subprocess.CalledProcessError as e: print("ERROR: ansible run failed, output was: \n") print(e.output) sys.exit(e.returncode) ansible_out = to_text(b_ansible_out)
ansible_out = to_text(b_ansible_out) parsed = json.loads(ansible_out[ansible_out.index('{'):]) ansible_facts = {} for fact in facts: try: ansible_facts[fact] = parsed['ansible_facts']['ansible_' + fact] except Exception: ansible_facts[fact] = "N/A" nicename = ansible_facts['distribution'] + ' ' + ansible_facts[ 'distribution_version'] output = { 'name': nicename, 'distro': { 'codename': distro.codename(), 'id': distro.id(), 'name': distro.name(), 'version': distro.version(), 'version_best': distro.version(best=True), 'lsb_release_info': distro.lsb_release_info(), 'os_release_info': distro.os_release_info(), }, 'input': fcont, 'platform.dist': dist, 'result': ansible_facts, } print(json.dumps(output, indent=4))