From 8db282ed927a1bce6283c3a398a0718ab380bb3c Mon Sep 17 00:00:00 2001 From: Tetja Rediske Date: Wed, 7 Jan 2026 17:41:43 +0100 Subject: [PATCH 1/3] Fixes Parsing for ClearLinux exposed by Gentoo changing os-release Quoting from " to ', also fixes NA parsing to strip booth kind of quotes --- lib/ansible/module_utils/facts/system/distribution.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index aeb78d789bff5c..68ffae2a6bd963 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -438,10 +438,10 @@ def parse_distribution_file_NA(self, name, data, path, collected_facts): for line in data.splitlines(): distribution = re.search("^NAME=(.*)", line) if distribution and name == 'NA': - na_facts['distribution'] = distribution.group(1).strip('"') + na_facts['distribution'] = distribution.group(1).strip('"').strip("'") version = re.search("^VERSION=(.*)", line) if version and collected_facts['distribution_version'] == 'NA': - na_facts['distribution_version'] = version.group(1).strip('"') + na_facts['distribution_version'] = version.group(1).strip('"').strip("'") return True, na_facts def parse_distribution_file_Coreos(self, name, data, path, collected_facts): @@ -489,6 +489,8 @@ def parse_distribution_file_ClearLinux(self, name, data, path, collected_facts): if 'Clear Linux' not in pname.groups()[0]: return False, clear_facts clear_facts['distribution'] = pname.groups()[0] + else: + return False, clear_facts version = re.search('VERSION_ID=(.*)', data) if version: clear_facts['distribution_major_version'] = version.groups()[0] From 7ff5b15eddfecf4f47878a09c183af9964028689 Mon Sep 17 00:00:00 2001 From: Tetja Rediske Date: Fri, 9 Jan 2026 22:53:44 +0100 Subject: [PATCH 2/3] Added Gentoo Test Information Added Changelog Fragment --- .../fragments/clearlinux-gentoo-parsing.yml | 3 ++ .../module_utils/facts/system/distribution.py | 4 +- .../system/distribution/fixtures/gentoo.json | 47 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/clearlinux-gentoo-parsing.yml create mode 100644 test/units/module_utils/facts/system/distribution/fixtures/gentoo.json diff --git a/changelogs/fragments/clearlinux-gentoo-parsing.yml b/changelogs/fragments/clearlinux-gentoo-parsing.yml new file mode 100644 index 00000000000000..7cf73a94e8210f --- /dev/null +++ b/changelogs/fragments/clearlinux-gentoo-parsing.yml @@ -0,0 +1,3 @@ +bugfixes: + - 'ansible_facts[os_*] - Contained wrong information, if ClearLinux parsing was tried before falling back to general os-release parsing' + diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index 68ffae2a6bd963..ee32605e4291e5 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -438,10 +438,10 @@ def parse_distribution_file_NA(self, name, data, path, collected_facts): for line in data.splitlines(): distribution = re.search("^NAME=(.*)", line) if distribution and name == 'NA': - na_facts['distribution'] = distribution.group(1).strip('"').strip("'") + na_facts['distribution'] = distribution.group(1).strip(DistributionFiles.STRIP_QUOTES) version = re.search("^VERSION=(.*)", line) if version and collected_facts['distribution_version'] == 'NA': - na_facts['distribution_version'] = version.group(1).strip('"').strip("'") + na_facts['distribution_version'] = version.group(1).strip(DistributionFiles.STRIP_QUOTES) return True, na_facts def parse_distribution_file_Coreos(self, name, data, path, collected_facts): diff --git a/test/units/module_utils/facts/system/distribution/fixtures/gentoo.json b/test/units/module_utils/facts/system/distribution/fixtures/gentoo.json new file mode 100644 index 00000000000000..759e8651f89e26 --- /dev/null +++ b/test/units/module_utils/facts/system/distribution/fixtures/gentoo.json @@ -0,0 +1,47 @@ +{ + "name": "Gentoo 2.18", + "distro": { + "codename": "n/a", + "id": "gentoo", + "name": "Gentoo", + "version": "2.18", + "version_best": "2.18", + "lsb_release_info": { + "lsb_version": "n/a", + "distributor_id": "Gentoo", + "description": "Gentoo Linux", + "release": "2.18", + "codename": "n/a" + }, + "os_release_info": { + "name": "Gentoo", + "id": "gentoo", + "pretty_name": "Gentoo Linux", + "version": "2.18", + "version_id": "2.18", + "home_url": "https://www.gentoo.org/", + "support_url": "https://www.gentoo.org/support/", + "bug_report_url": "https://bugs.gentoo.org/", + "ansi_color": "1;32" + } + }, + "input": { + "/etc/os-release": "NAME='Gentoo'\nID='gentoo'\nPRETTY_NAME='Gentoo Linux'\nVERSION='2.18'\nVERSION_ID='2.18'\nHOME_URL='https://www.gentoo.org/'\nSUPPORT_URL='https://www.gentoo.org/support/'\nBUG_REPORT_URL='https://bugs.gentoo.org/'\nANSI_COLOR='1;32'\n", + "/etc/gentoo-release": "Gentoo Base System release 2.18\n", + "/etc/lsb-release": "DISTRIB_ID=\"Gentoo\"\n", + "/usr/lib/os-release": "NAME='Gentoo'\nID='gentoo'\nPRETTY_NAME='Gentoo Linux'\nVERSION='2.18'\nVERSION_ID='2.18'\nHOME_URL='https://www.gentoo.org/'\nSUPPORT_URL='https://www.gentoo.org/support/'\nBUG_REPORT_URL='https://bugs.gentoo.org/'\nANSI_COLOR='1;32'\n" + }, + "platform.dist": [ + "gentoo", + "2.18", + "n/a" + ], + "result": { + "distribution": "Gentoo", + "distribution_version": "2.18", + "distribution_release": "n/a", + "distribution_major_version": "2", + "os_family": "Gentoo" + }, + "platform.release": "6.18.2-p1-gentoo-dist" +} From 8100c7719251c431c87ab94b3945f5fa6b8ff03f Mon Sep 17 00:00:00 2001 From: Tetja Rediske Date: Fri, 9 Jan 2026 23:38:33 +0100 Subject: [PATCH 3/3] removed empty line --- changelogs/fragments/clearlinux-gentoo-parsing.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/changelogs/fragments/clearlinux-gentoo-parsing.yml b/changelogs/fragments/clearlinux-gentoo-parsing.yml index 7cf73a94e8210f..3216991aa59012 100644 --- a/changelogs/fragments/clearlinux-gentoo-parsing.yml +++ b/changelogs/fragments/clearlinux-gentoo-parsing.yml @@ -1,3 +1,2 @@ bugfixes: - 'ansible_facts[os_*] - Contained wrong information, if ClearLinux parsing was tried before falling back to general os-release parsing' -