Esempio n. 1
0
def get_distribution_version():
    '''
    :rtype: NativeString or None
    :returns: A string representation of the version of the distribution.  None if this is not run
        on a Linux machine
    '''
    version = None
    if platform.system() == 'Linux':
        version = distro.version()
    return version
Esempio n. 2
0
def get_distribution_version():
    '''
    Get the version of the Linux distribution the code is running on

    :rtype: NativeString or None
    :returns: A string representation of the version of the distribution. If it cannot determine
        the version, it returns empty string. If this is not run on a Linux machine it returns None
    '''
    version = None
    if platform.system() == 'Linux':
        version = distro.version()
    return version
Esempio n. 3
0
def get_distribution_version():
    '''
    Get the version of the Linux distribution the code is running on

    :rtype: NativeString or None
    :returns: A string representation of the version of the distribution. If it cannot determine
        the version, it returns empty string. If this is not run on a Linux machine it returns None
    '''
    version = None

    needs_best_version = frozenset((
        u'centos',
        u'debian',
    ))

    if platform.system() == 'Linux':
        version = distro.version()
        distro_id = distro.id()

        if version is not None:
            if distro_id in needs_best_version:
                version_best = distro.version(best=True)

                # CentoOS maintainers believe only the major version is appropriate
                # but Ansible users desire minor version information, e.g., 7.5.
                # https://github.com/ansible/ansible/issues/50141#issuecomment-449452781
                if distro_id == u'centos':
                    version = u'.'.join(version_best.split(u'.')[:2])

                # Debian does not include minor version in /etc/os-release.
                # Bug report filed upstream requesting this be added to /etc/os-release
                # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=931197
                if distro_id == u'debian':
                    version = version_best

        else:
            version = u''

    return version
Esempio n. 4
0
    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()
Esempio n. 5
0
    '/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)
Esempio n. 6
0
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))