Port from plaform.dist to ansible.module_utils.distro.linux_distribution

ci_complete
This commit is contained in:
Toshio Kuratomi 2018-12-10 17:04:14 -08:00
commit 61b1daa65f
10 changed files with 248 additions and 114 deletions

View file

@ -20,8 +20,9 @@ import os
import platform
import re
from ansible.module_utils.common.sys_info import get_distribution, get_distribution_version, \
get_distribution_codename
from ansible.module_utils.facts.utils import get_file_content
from ansible.module_utils.facts.collector import BaseFactCollector
@ -111,7 +112,7 @@ class DistributionFiles:
dist_file_dict = {}
if name in self.SEARCH_STRING:
# look for the distribution string in the data and replace according to RELEASE_NAME_MAP
# only the distribution name is set, the version is assumed to be correct from platform.dist()
# only the distribution name is set, the version is assumed to be correct from distro.linux_distribution()
if self.SEARCH_STRING[name] in dist_file_content:
# this sets distribution=RedHat if 'Red Hat' shows up in data
dist_file_dict['distribution'] = name
@ -152,12 +153,15 @@ class DistributionFiles:
def _guess_distribution(self):
# try to find out which linux distribution this is
dist = platform.dist()
dist = (get_distribution(), get_distribution_version(), get_distribution_codename())
distribution_guess = {}
distribution_guess['distribution'] = dist[0].capitalize() or 'NA'
distribution_guess['distribution'] = dist[0] or 'NA'
distribution_guess['distribution_version'] = dist[1] or 'NA'
distribution_guess['distribution_major_version'] = dist[1].split('.')[0] or 'NA'
distribution_guess['distribution_release'] = dist[2] or 'NA'
distribution_guess['distribution_major_version'] = \
distribution_guess['distribution_version'].split('.')[0] or 'NA'
# distribution_release can be the empty string
distribution_guess['distribution_release'] = 'NA' if dist[2] is None else dist[2]
return distribution_guess
def process_dist_files(self):
@ -362,8 +366,7 @@ class DistributionFiles:
def parse_distribution_file_Coreos(self, name, data, path, collected_facts):
coreos_facts = {}
# FIXME: pass in ro copy of facts for this kind of thing
dist = platform.dist()
distro = dist[0]
distro = get_distribution()
if distro.lower() == 'coreos':
if not data: