From a223ea5185aedb4fa7c1a8c60270a7953414f76b Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 1 Dec 2020 20:31:25 +0530 Subject: [PATCH] distribution - handle NetBSD OS Family (#70799) Fixes: #43739 Signed-off-by: Abhijeet Kasurde --- .../fragments/distribution_support_netbsd.yml | 2 ++ .../module_utils/facts/system/distribution.py | 14 ++++++++--- .../distribution/fixtures/netbsd_8.2.json | 25 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/distribution_support_netbsd.yml create mode 100644 test/units/module_utils/facts/system/distribution/fixtures/netbsd_8.2.json diff --git a/changelogs/fragments/distribution_support_netbsd.yml b/changelogs/fragments/distribution_support_netbsd.yml new file mode 100644 index 00000000000..84e040a0a20 --- /dev/null +++ b/changelogs/fragments/distribution_support_netbsd.yml @@ -0,0 +1,2 @@ +minor_changes: +- distribution - handle NetBSD OS Family (https://github.com/ansible/ansible/issues/43739). diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index 2e8f5865fbe..ad56594567f 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -507,7 +507,8 @@ class Distribution(object): 'Darwin': ['MacOSX'], 'FreeBSD': ['FreeBSD', 'TrueOS'], 'ClearLinux': ['Clear Linux OS', 'Clear Linux Mix'], - 'DragonFly': ['DragonflyBSD', 'DragonFlyBSD', 'Gentoo/DragonflyBSD', 'Gentoo/DragonFlyBSD']} + 'DragonFly': ['DragonflyBSD', 'DragonFlyBSD', 'Gentoo/DragonflyBSD', 'Gentoo/DragonFlyBSD'], + 'NetBSD': ['NetBSD'], } OS_FAMILY = {} for family, names in OS_FAMILY_MAP.items(): @@ -617,9 +618,16 @@ class Distribution(object): def get_distribution_NetBSD(self): netbsd_facts = {} - # FIXME: poking at self.facts, should eventually make these each a collector platform_release = platform.release() - netbsd_facts['distribution_major_version'] = platform_release.split('.')[0] + netbsd_facts['distribution_release'] = platform_release + rc, out, dummy = self.module.run_command("/sbin/sysctl -n kern.version") + match = re.match(r'NetBSD\s(\d+)\.(\d+)\s\((GENERIC)\).*', out) + if match: + netbsd_facts['distribution_major_version'] = match.group(1) + netbsd_facts['distribution_version'] = '%s.%s' % match.groups()[:2] + else: + netbsd_facts['distribution_major_version'] = platform_release.split('.')[0] + netbsd_facts['distribution_version'] = platform_release return netbsd_facts def get_distribution_SMGL(self): diff --git a/test/units/module_utils/facts/system/distribution/fixtures/netbsd_8.2.json b/test/units/module_utils/facts/system/distribution/fixtures/netbsd_8.2.json new file mode 100644 index 00000000000..65c4ed61172 --- /dev/null +++ b/test/units/module_utils/facts/system/distribution/fixtures/netbsd_8.2.json @@ -0,0 +1,25 @@ +{ + "name": "NetBSD 8.2 (GENERIC) #0", + "input": {}, + "platform.system": "NetBSD", + "platform.release": "8.2", + "command_output": { + "/sbin/sysctl -n kern.version": "NetBSD 8.2 (GENERIC) #0: Tue Mar 31 05:08:40 UTC 2020\n mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC" + }, + "distro": { + "codename": "", + "id": "netbsd", + "name": "NetBSD", + "version": "8.2", + "version_best": "8.2", + "os_release_info": {}, + "lsb_release_info": {} + }, + "result": { + "distribution": "NetBSD", + "distribution_major_version": "8", + "distribution_release": "8.2", + "os_family": "NetBSD", + "distribution_version": "8.2" + } +} \ No newline at end of file