1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix wrong distribution facts on SLES/openSUSE

This commit is contained in:
Alexander Gubin 2015-01-29 14:54:53 +01:00
parent fef435cc2a
commit 5dec45e24a

View file

@ -351,21 +351,47 @@ class Facts(object):
data = get_file_content(path) data = get_file_content(path)
if 'suse' in data.lower(): if 'suse' in data.lower():
if path == '/etc/os-release': if path == '/etc/os-release':
release = re.search("PRETTY_NAME=[^(]+ \(?([^)]+?)\)", data) for line in data.splitlines():
distdata = get_file_content(path).split('\n')[0] distribution = re.search("^NAME=(.*)", line)
self.facts['distribution'] = distdata.split('=')[1] if distribution:
if release: self.facts['distribution'] = distribution.group(1).strip('"')
self.facts['distribution_release'] = release.groups()[0] distribution_version = re.search('^VERSION_ID="?([0-9]+\.?[0-9]*)"?', line) # example pattern are 13.04 13.0 13
break if distribution_version:
self.facts['distribution_version'] = distribution_version.group(1)
if 'open' in data.lower():
release = re.search("^PRETTY_NAME=[^(]+ \(?([^)]+?)\)", line)
if release:
self.facts['distribution_release'] = release.groups()[0]
elif 'enterprise' in data.lower():
release = re.search('^VERSION_ID="?[0-9]+\.?([0-9]*)"?', line) # SLES doesn't got funny release names
if release:
release = release.group(1)
else:
release = "0" # no minor number, so it is the first release
self.facts['distribution_release'] = release
elif path == '/etc/SuSE-release': elif path == '/etc/SuSE-release':
data = data.splitlines() if 'open' in data.lower():
distdata = get_file_content(path).split('\n')[0] data = data.splitlines()
self.facts['distribution'] = distdata.split()[0] distdata = get_file_content(path).split('\n')[0]
for line in data: self.facts['distribution'] = distdata.split()[0]
release = re.search('CODENAME *= *([^\n]+)', line) for line in data:
if release: release = re.search('CODENAME *= *([^\n]+)', line)
self.facts['distribution_release'] = release.groups()[0].strip() if release:
break self.facts['distribution_release'] = release.groups()[0].strip()
break
elif 'enterprise' in data.lower():
lines = data.splitlines()
distribution = lines[0].split()[0]
if "Server" in data:
self.facts['distribution'] = "SLES"
elif "Desktop" in data:
self.facts['distribution'] = "SLED"
for line in lines:
release = re.search('PATCHLEVEL = ([0-9]+)', line) # SLES doesn't got funny release names
if release:
self.facts['distribution_release'] = release.group(1)
self.facts['distribution_version'] = self.facts['distribution_version'] + '.' + release.group(1)
break
elif name == 'Debian': elif name == 'Debian':
data = get_file_content(path) data = get_file_content(path)
if 'Debian' in data: if 'Debian' in data: