Get minor version number for CentOS and Debian (#57814)
* Get the most detailed version number from distro.version() for CentOS and Debian * Update tests and fixtures * Update fixture generation script to gather distro info and work with Python 3 * Update LinuxMint fixtures * Cleanup fixture formatting * Improvements based on feedback from abadger: - use unicode since that is what distro returns - use frozenset with a tuple - include link Debian to bug
This commit is contained in:
parent
2f91266aa9
commit
ab6a9ef130
3 changed files with 514 additions and 305 deletions
|
@ -16,6 +16,7 @@ import json
|
|||
import sys
|
||||
|
||||
from ansible.module_utils import distro
|
||||
from ansible.module_utils._text import to_text
|
||||
|
||||
|
||||
filelist = [
|
||||
|
@ -53,13 +54,14 @@ dist = distro.linux_distribution(full_distribution_name=False)
|
|||
facts = ['distribution', 'distribution_version', 'distribution_release', 'distribution_major_version', 'os_family']
|
||||
|
||||
try:
|
||||
ansible_out = subprocess.check_output(
|
||||
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)
|
||||
parsed = json.loads(ansible_out[ansible_out.index('{'):])
|
||||
ansible_facts = {}
|
||||
for fact in facts:
|
||||
|
@ -72,6 +74,13 @@ nicename = ansible_facts['distribution'] + ' ' + ansible_facts['distribution_ver
|
|||
|
||||
output = {
|
||||
'name': nicename,
|
||||
'distro': {
|
||||
'codename': distro.codename(),
|
||||
'id': distro.id(),
|
||||
'name': distro.name(),
|
||||
'version': distro.version(),
|
||||
'version_best': distro.version(best=True),
|
||||
},
|
||||
'input': fcont,
|
||||
'platform.dist': dist,
|
||||
'result': ansible_facts,
|
||||
|
|
|
@ -50,8 +50,35 @@ def get_distribution_version():
|
|||
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
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue