From ec9769c82fc1818b31fd3c4a31de4cba9a5c2ab8 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Sat, 20 Jan 2018 15:05:53 -0500 Subject: [PATCH] Facts distribution clear linux 31501 (#32453) The search string used to look for Clear Linux was changed in 45a9f967749ec68e2077fe1d1d32dd37660ab376 to be more specific, but was too specific. Now finding a substring match for 'Clear Linux' in /usr/lib/os-release is enough to consider a match. Since the details of the full name in os-release varies ('Clear Linux Software for Intel Architecture', 'Clear Linux OS for Intel Architecture', etc) the search string match was failing and would fall back to the 'first word in the release file' method resulting in ansible_distribution='NAME="Clear' Also add a meta fact indicating which search string was matched. Test case info from: https://github.com/ansible/ansible/issues/31501#issuecomment-340861535 Fixes #31501 --- .../gen_distribution_version_testcase.py | 1 + .../module_utils/facts/system/distribution.py | 3 +- .../module_utils/test_distribution_version.py | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/hacking/tests/gen_distribution_version_testcase.py b/hacking/tests/gen_distribution_version_testcase.py index bc2ab3c09ca..fdd0a058bc4 100755 --- a/hacking/tests/gen_distribution_version_testcase.py +++ b/hacking/tests/gen_distribution_version_testcase.py @@ -32,6 +32,7 @@ filelist = [ '/etc/altlinux-release', '/etc/os-release', '/etc/coreos/update.conf', + '/usr/lib/os-release', ] fcont = {} diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index 7e3cbcf6c15..992aca13c91 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -82,7 +82,7 @@ class DistributionFiles: 'OracleLinux': 'Oracle Linux', 'RedHat': 'Red Hat', 'Altlinux': 'ALT Linux', - 'ClearLinux': 'Clear Linux Software for Intel Architecture', + 'ClearLinux': 'Clear Linux', 'SMGL': 'Source Mage GNU/Linux', } @@ -115,6 +115,7 @@ class DistributionFiles: 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 + dist_file_dict['distribution_file_search_string'] = self.SEARCH_STRING[name] else: # this sets distribution to what's in the data, e.g. CentOS, Scientific, ... dist_file_dict['distribution'] = dist_file_content.split()[0] diff --git a/test/units/module_utils/test_distribution_version.py b/test/units/module_utils/test_distribution_version.py index 06d9162000b..b806099a88c 100644 --- a/test/units/module_utils/test_distribution_version.py +++ b/test/units/module_utils/test_distribution_version.py @@ -839,6 +839,37 @@ DISTRIB_DESCRIPTION="CoreOS 976.0.0 (Coeur Rouge)" } }, + # ClearLinux https://github.com/ansible/ansible/issues/31501#issuecomment-340861535 + { + "platform.dist": [ + "Clear Linux OS for Intel Architecture", + "18450", + "clear-linux-os" + ], + "input": { + "/usr/lib/os-release": ''' +NAME="Clear Linux OS for Intel Architecture" +VERSION=1 +ID=clear-linux-os +VERSION_ID=18450 +PRETTY_NAME="Clear Linux OS for Intel Architecture" +ANSI_COLOR="1;35" +HOME_URL="https://clearlinux.org" +SUPPORT_URL="https://clearlinux.org" +BUG_REPORT_URL="mailto:dev@lists.clearlinux.org" +PRIVACY_POLICY_URL="http://www.intel.com/privacy" +''' + }, + "name": "Clear Linux OS for Intel Architecture 1", + "result": { + "distribution_release": "clear-linux-os", + "distribution": "ClearLinux", + "distribution_major_version": "18450", + "os_family": "ClearLinux", + "distribution_version": "18450" + } + }, + # ArchLinux with no /etc/arch-release but with a /etc/os-release with NAME=Arch Linux # The fact needs to map 'Arch Linux' to 'Archlinux' for compat with 2.3 and earlier facts {