Skip to content

Commit

Permalink
(FACT-3163) Add support for OpenBSD
Browse files Browse the repository at this point in the history
Most inspiration taken from FreeBSD, rest from other OS,
and some own creations. Not all core facts supported, but
makes puppet facts works well, as well as puppet agent --test

Developed/Tested on OpenBSD 7.2, AMD64, Puppet 7.20.0, Ruby 3.1.2

also disable RuboCop Metrics/PerceivedComplexity
and Metrics/CyclomaticComplexity
as suggested by @joshcooper

Additionally:
Case insensitive OS detection

ran into trouble when facter installed via puppetserver gem install,
there the OS returned seems to be OpenBSD instead of all lowercase.
  • Loading branch information
buzzdeee committed Feb 25, 2024
1 parent fce69ea commit fff8397
Show file tree
Hide file tree
Showing 131 changed files with 3,339 additions and 44 deletions.
5 changes: 3 additions & 2 deletions lib/facter/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ module Config
]
},
{
'Bsd' => [
'Freebsd'
'Bsd' => %w[
Freebsd
Openbsd
]
},
'Solaris',
Expand Down
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/augeas/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Augeas
class Version
FACT_NAME = 'augeas.version'
ALIASES = 'augeasversion'

def call_the_resolver
fact_value = Facter::Resolvers::Augeas.resolve(:augeas_version)

[Facter::ResolvedFact.new(FACT_NAME, fact_value),
Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/bios/vendor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Bios
class Vendor
FACT_NAME = 'dmi.bios.vendor'
ALIASES = 'bios_vendor'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:bios_vendor)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/bios/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Bios
class Version
FACT_NAME = 'dmi.bios.version'
ALIASES = 'bios_version'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:bios_version)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/facter/facts/openbsd/dmi/manufacturer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
class Manufacturer
FACT_NAME = 'dmi.manufacturer'
ALIASES = 'manufacturer'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:sys_vendor)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/product/name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Product
class Name
FACT_NAME = 'dmi.product.name'
ALIASES = 'productname'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_name)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/product/serial_number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Product
class SerialNumber
FACT_NAME = 'dmi.product.serial_number'
ALIASES = 'serialnumber'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_serial)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/product/uuid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Product
class Uuid
FACT_NAME = 'dmi.product.uuid'
ALIASES = 'uuid'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_uuid)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
23 changes: 23 additions & 0 deletions lib/facter/facts/openbsd/ec2_metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Ec2Metadata
FACT_NAME = 'ec2_metadata'

def call_the_resolver
return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?

fact_value = Facter::Resolvers::Ec2.resolve(:metadata)

Facter::ResolvedFact.new(FACT_NAME, fact_value&.empty? ? nil : fact_value)
end

private

def aws_hypervisors?
Facter::Util::Facts::Posix::VirtualDetector.platform =~ /kvm|xen|aws/
end
end
end
end
23 changes: 23 additions & 0 deletions lib/facter/facts/openbsd/ec2_userdata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Ec2Userdata
FACT_NAME = 'ec2_userdata'

def call_the_resolver
return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?

fact_value = Facter::Resolvers::Ec2.resolve(:userdata)

Facter::ResolvedFact.new(FACT_NAME, fact_value&.empty? ? nil : fact_value)
end

private

def aws_hypervisors?
Facter::Util::Facts::Posix::VirtualDetector.platform =~ /kvm|xen|aws/
end
end
end
end
14 changes: 14 additions & 0 deletions lib/facter/facts/openbsd/facterversion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Facterversion
FACT_NAME = 'facterversion'

def call_the_resolver
fact_value = Facter::Resolvers::Facterversion.resolve(:facterversion)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
16 changes: 16 additions & 0 deletions lib/facter/facts/openbsd/identity/gid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class Gid
FACT_NAME = 'identity.gid'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:gid)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facter/facts/openbsd/identity/group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class Group
FACT_NAME = 'identity.group'
ALIASES = 'gid'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:group)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/facter/facts/openbsd/identity/privileged.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class Privileged
FACT_NAME = 'identity.privileged'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:privileged)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/facter/facts/openbsd/identity/uid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class Uid
FACT_NAME = 'identity.uid'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:uid)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/facter/facts/openbsd/identity/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class User
FACT_NAME = 'identity.user'
ALIASES = 'id'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:user)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/openbsd/ipaddress6_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Ipaddress6Interfaces
FACT_NAME = 'ipaddress6_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("ipaddress6_#{interface_name}", info[:ip6], :legacy) if info[:ip6]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/openbsd/ipaddress_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Openbsd
class IpaddressInterfaces
FACT_NAME = 'ipaddress_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("ipaddress_#{interface_name}", info[:ip], :legacy) if info[:ip]
end

arr
end
end
end
end
21 changes: 21 additions & 0 deletions lib/facter/facts/openbsd/is_virtual.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Facts
module Openbsd
class IsVirtual
FACT_NAME = 'is_virtual'

def call_the_resolver
fact_value = Facter::Util::Facts::Posix::VirtualDetector.platform

Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value))
end

private

def check_if_virtual(found_vm)
Facter::Util::Facts::PHYSICAL_HYPERVISORS.count(found_vm).zero?
end
end
end
end
14 changes: 14 additions & 0 deletions lib/facter/facts/openbsd/kernel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Kernel
FACT_NAME = 'kernel'

def call_the_resolver
fact_value = Facter::Resolvers::Uname.resolve(:kernelname)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
14 changes: 14 additions & 0 deletions lib/facter/facts/openbsd/kernelrelease.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Kernelrelease
FACT_NAME = 'kernelrelease'

def call_the_resolver
fact_value = Facter::Resolvers::Uname.resolve(:kernelrelease)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
Loading

0 comments on commit fff8397

Please sign in to comment.