* [stable-2.8] 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
(cherry picked from commit ab6a9ef130
)
Co-authored-by: Sam Doran <sdoran@redhat.com>
* Add a changelog for the version number in facts change
This commit is contained in:
parent
a553474ca8
commit
6e7fcf38a8
4 changed files with 520 additions and 305 deletions
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
bugfixes:
|
||||
- facts - Restore the minor version number for CentOS and Debian. Debian has
|
||||
a minor release number but doesn't put it in os-release. CentOS doesn't have
|
||||
a minor version number but users want to try to match CentOS versions to RHEL
|
||||
equivalents so we grab the RHEL version instead.
|
|
@ -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