From d1ad0057c6cfb31dacb26509a2cfe45644e73439 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 22 Apr 2022 16:07:50 +0200 Subject: [PATCH] (FACT-3114) Arch Linux: Implement os version facts From this branch: ``` $ bundle exec facter os { architecture => "x86_64", distro => { codename => "n/a", description => "Arch Linux", id => "Arch", release => { full => "rolling", major => "rolling", minor => null }, specification => "n/a" }, family => "Archlinux", hardware => "x86_64", name => "Archlinux", release => { full => "6.9.3-arch1-1", major => "6", minor => "9" }, selinux => { enabled => false } } ``` Facter 3 on Archlinux: ``` $ facter os { architecture => "x86_64", distro => { codename => "n/a", description => "Arch Linux", id => "Arch", release => { full => "rolling", major => "rolling" }, specification => "n/a" }, family => "Archlinux", hardware => "x86_64", name => "Archlinux", release => { full => "6.9.3-arch1-1", major => "6", minor => "9" }, selinux => { enabled => false } } ``` --- lib/facter/config.rb | 1 + lib/facter/facts/archlinux/os/release.rb | 21 ++++++++++++++++++++ lib/facter/framework/core/file_loader.rb | 3 +++ lib/facter/framework/detector/os_detector.rb | 1 + 4 files changed, 26 insertions(+) create mode 100644 lib/facter/facts/archlinux/os/release.rb diff --git a/lib/facter/config.rb b/lib/facter/config.rb index 4ae2dc5d79..057598e95a 100644 --- a/lib/facter/config.rb +++ b/lib/facter/config.rb @@ -34,6 +34,7 @@ module Config Sled ] }, + 'Archlinux', 'Gentoo', 'Alpine', 'Photon', diff --git a/lib/facter/facts/archlinux/os/release.rb b/lib/facter/facts/archlinux/os/release.rb new file mode 100644 index 0000000000..d0432cea5e --- /dev/null +++ b/lib/facter/facts/archlinux/os/release.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Facts + module Archlinux + module Os + class Release + FACT_NAME = 'os.release' + + def call_the_resolver + # Arch Linux is rolling release and has no version numbers + # For historical reasons facter used the kernel version as OS version on Arch Linux + kernelrelease = Facter::Resolvers::Uname.resolve(:kernelrelease) + versions = kernelrelease.split('.') + hash = { full: kernelrelease, major: versions[0], minor: versions[1] } + + Facter::ResolvedFact.new(FACT_NAME, hash) + end + end + end + end +end diff --git a/lib/facter/framework/core/file_loader.rb b/lib/facter/framework/core/file_loader.rb index 27aad88e15..451013c194 100644 --- a/lib/facter/framework/core/file_loader.rb +++ b/lib/facter/framework/core/file_loader.rb @@ -246,6 +246,9 @@ require_relative '../../resolvers/amzn/os_release_rpm' + when 'archlinux' + require_relative '../../facts/archlinux/os/release' + when 'bsd' require_relative '../../facts/bsd/kernelmajversion' require_relative '../../facts/bsd/kernelversion' diff --git a/lib/facter/framework/detector/os_detector.rb b/lib/facter/framework/detector/os_detector.rb index 4b0e9f5640..3b4198ab33 100644 --- a/lib/facter/framework/detector/os_detector.rb +++ b/lib/facter/framework/detector/os_detector.rb @@ -68,6 +68,7 @@ def detect_family def detect_based_on_release_file @identifier = :devuan if File.readable?('/etc/devuan_version') + @identifier = :archlinux if File.readable?('/etc/arch-release') end def detect_distro