# frozen_string_literal: true
# Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version # Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version
# #
# Purpose: Return various facts about the PE state of the system # Purpose: Return various facts about the PE state of the system
...@@ -10,24 +8,18 @@ ...@@ -10,24 +8,18 @@
# #
# Caveats: # Caveats:
# #
# Fact: pe_version
Facter.add('pe_version') do Facter.add('pe_version') do
setcode do setcode do
found_version = Facter.value('pe_build')
unless found_version
puppet_ver = Facter.value('puppetversion') puppet_ver = Facter.value('puppetversion')
unless puppet_ver.nil? if !puppet_ver.nil?
pe_ver = puppet_ver.match(%r{Puppet Enterprise (\d+\.\d+\.\d+)}) pe_ver = puppet_ver.match(%r{Puppet Enterprise (\d+\.\d+\.\d+)})
found_version = pe_ver[1] if pe_ver pe_ver[1] if pe_ver
end else
nil
end end
found_version
end end
end end
# Fact: is_pe
Facter.add('is_pe') do Facter.add('is_pe') do
setcode do setcode do
if Facter.value(:pe_version).to_s.empty? if Facter.value(:pe_version).to_s.empty?
...@@ -38,9 +30,8 @@ Facter.add('is_pe') do ...@@ -38,9 +30,8 @@ Facter.add('is_pe') do
end end
end end
# Fact: pe_major_version
Facter.add('pe_major_version') do Facter.add('pe_major_version') do
confine is_pe: true confine :is_pe => true
setcode do setcode do
pe_version = Facter.value(:pe_version) pe_version = Facter.value(:pe_version)
if pe_version if pe_version
...@@ -49,9 +40,8 @@ Facter.add('pe_major_version') do ...@@ -49,9 +40,8 @@ Facter.add('pe_major_version') do
end end
end end
# Fact: pe_minor_version
Facter.add('pe_minor_version') do Facter.add('pe_minor_version') do
confine is_pe: true confine :is_pe => true
setcode do setcode do
pe_version = Facter.value(:pe_version) pe_version = Facter.value(:pe_version)
if pe_version if pe_version
...@@ -60,9 +50,8 @@ Facter.add('pe_minor_version') do ...@@ -60,9 +50,8 @@ Facter.add('pe_minor_version') do
end end
end end
# Fact: pe_patch_version
Facter.add('pe_patch_version') do Facter.add('pe_patch_version') do
confine is_pe: true confine :is_pe => true
setcode do setcode do
pe_version = Facter.value(:pe_version) pe_version = Facter.value(:pe_version)
if pe_version if pe_version
......
# frozen_string_literal: true
# These facter facts return the value of the Puppet vardir and environment path # These facter facts return the value of the Puppet vardir and environment path
# settings for the node running puppet or puppet agent. The intent is to # settings for the node running puppet or puppet agent. The intent is to
# enable Puppet modules to automatically have insight into a place where they # enable Puppet modules to automatically have insight into a place where they
# can place variable data, or for modules running on the puppet server to know # can place variable data, or for modules running on the puppet master to know
# where environments are stored. # where environments are stored.
# #
# The values should be directly usable in a File resource path attribute. # The values should be directly usable in a File resource path attribute.
...@@ -18,7 +16,7 @@ rescue LoadError => e ...@@ -18,7 +16,7 @@ rescue LoadError => e
load rb_file if File.exist?(rb_file) || raise(e) load rb_file if File.exist?(rb_file) || raise(e)
end end
# Facter fact returns the value of the Puppet vardir # These will be nil if Puppet is not available.
Facter.add(:puppet_vardir) do Facter.add(:puppet_vardir) do
setcode do setcode do
Facter::Util::PuppetSettings.with_puppet do Facter::Util::PuppetSettings.with_puppet do
...@@ -27,7 +25,6 @@ Facter.add(:puppet_vardir) do ...@@ -27,7 +25,6 @@ Facter.add(:puppet_vardir) do
end end
end end
# Facter fact returns the value of the Puppet environment path
Facter.add(:puppet_environmentpath) do Facter.add(:puppet_environmentpath) do
setcode do setcode do
Facter::Util::PuppetSettings.with_puppet do Facter::Util::PuppetSettings.with_puppet do
...@@ -36,7 +33,6 @@ Facter.add(:puppet_environmentpath) do ...@@ -36,7 +33,6 @@ Facter.add(:puppet_environmentpath) do
end end
end end
# Facter fact returns the value of the Puppet server
Facter.add(:puppet_server) do Facter.add(:puppet_server) do
setcode do setcode do
Facter::Util::PuppetSettings.with_puppet do Facter::Util::PuppetSettings.with_puppet do
......
# frozen_string_literal: true # A facter fact to determine the root home directory.
# This varies on PE supported platforms and may be
# root_home.rb # reconfigured by the end user.
module Facter::Util::RootHome module Facter::Util::RootHome
# @summary
# A facter fact to determine the root home directory.
# This varies on PE supported platforms and may be
# reconfigured by the end user.
class << self class << self
# determines the root home directory
def returnt_root_home def returnt_root_home
root_ent = Facter::Util::Resolution.exec('getent passwd root') root_ent = Facter::Util::Resolution.exec('getent passwd root')
# The home directory is the sixth element in the passwd entry # The home directory is the sixth element in the passwd entry
...@@ -23,7 +18,7 @@ Facter.add(:root_home) do ...@@ -23,7 +18,7 @@ Facter.add(:root_home) do
end end
Facter.add(:root_home) do Facter.add(:root_home) do
confine kernel: :darwin confine :kernel => :darwin
setcode do setcode do
str = Facter::Util::Resolution.exec('dscacheutil -q user -a name root') str = Facter::Util::Resolution.exec('dscacheutil -q user -a name root')
hash = {} hash = {}
...@@ -36,12 +31,12 @@ Facter.add(:root_home) do ...@@ -36,12 +31,12 @@ Facter.add(:root_home) do
end end
Facter.add(:root_home) do Facter.add(:root_home) do
confine kernel: :aix confine :kernel => :aix
root_home = nil root_home = nil
setcode do setcode do
str = Facter::Util::Resolution.exec('lsuser -c -a home root') str = Facter::Util::Resolution.exec('lsuser -c -a home root')
str&.split("\n")&.each do |line| str && str.split("\n").each do |line|
next if %r{^#}.match?(line) next if line =~ %r{^#}
root_home = line.split(%r{:})[1] root_home = line.split(%r{:})[1]
end end
root_home root_home
......
# frozen_string_literal: true
# Fact: service_provider # Fact: service_provider
# #
# Purpose: Returns the default provider Puppet will choose to manage services # Purpose: Returns the default provider Puppet will choose to manage services
...@@ -14,6 +12,6 @@ require 'puppet/type/service' ...@@ -14,6 +12,6 @@ require 'puppet/type/service'
Facter.add(:service_provider) do Facter.add(:service_provider) do
setcode do setcode do
Puppet::Type.type(:service).newservice(name: 'dummy')[:provider].to_s Puppet::Type.type(:service).newservice(:name => 'dummy')[:provider].to_s
end end
end end
# frozen_string_literal: true
# A method to evaluate a Facter code block if puppet is loaded. # A method to evaluate a Facter code block if puppet is loaded.
module Facter::Util::PuppetSettings module Facter::Util::PuppetSettings
# This method is intended to provide a convenient way to evaluate a # This method is intended to provide a convenient way to evaluate a
......
# frozen_string_literal: true # Function to print deprecation warnings, Logs a warning once for a given key. The uniqueness key - can appear once.
# The msg is the message text including any positional information that is formatted by the user/caller of the method.
# Function to print deprecation warnings, Logs a warning once for a given key. # It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message),
# # :off (no message / error is displayed) and :warning (default, outputs a warning) *Type*: String, String.
# The uniqueness key - can appear once.
# The msg is the message text including any positional information that is formatted by the
# user/caller of the method.
# It is affected by the puppet setting 'strict', which can be set to :error
# (outputs as an error message), :off (no message / error is displayed) and :warning
# (default, outputs a warning) *Type*: String, String.
# #
Puppet::Functions.create_function(:deprecation) do Puppet::Functions.create_function(:deprecation) do
# @param key
# @param message
# @return deprecated warnings
dispatch :deprecation do dispatch :deprecation do
param 'String', :key param 'String', :key
param 'String', :message param 'String', :message
...@@ -27,7 +19,7 @@ Puppet::Functions.create_function(:deprecation) do ...@@ -27,7 +19,7 @@ Puppet::Functions.create_function(:deprecation) do
end end
# depending on configuration setting of strict # depending on configuration setting of strict
case Puppet.settings[:strict] case Puppet.settings[:strict]
when :off when :off # rubocop:disable Lint/EmptyWhen : Is required to prevent false errors
# do nothing # do nothing
when :error when :error
raise("deprecation. #{key}. #{message}") raise("deprecation. #{key}. #{message}")
......
# frozen_string_literal: true
# @summary
# Digs into the facts hash using dot-notation # Digs into the facts hash using dot-notation
# #
# Supports the use of dot-notation for referring to structured facts. If a fact requested # Example usage:
# does not exist, returns Undef.
# #
# @example Example usage:
# fact('osfamily') # fact('osfamily')
# fact('os.architecture') # fact('os.architecture')
# #
# @example Array indexing: # Array indexing:
#
# fact('mountpoints."/dev".options.1') # fact('mountpoints."/dev".options.1')
# #
# @example Fact containing a "." in the name: # Fact containing a "." in the name:
#
# fact('vmware."VRA.version"') # fact('vmware."VRA.version"')
# #
Puppet::Functions.create_function(:fact) do Puppet::Functions.create_function(:fact) do
# @param fact_name
# The name of the fact to check
#
# @return
# All information retrieved on the given fact_name
dispatch :fact do dispatch :fact do
param 'String', :fact_name param 'String', :fact_name
end end
......
# frozen_string_literal: true # Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks.
# @summary
# Boolean check to determine whether a variable is of a given data type.
# This is equivalent to the `=~` type checks.
# #
# @example Example Usage: # @example how to check a data type
# # check a data type # # check a data type
# foo = 3 # foo = 3
# $bar = [1,2,3] # $bar = [1,2,3]
...@@ -24,20 +20,12 @@ ...@@ -24,20 +20,12 @@
# See the `assert_type()` function for flexible ways to assert the type of a value. # See the `assert_type()` function for flexible ways to assert the type of a value.
# #
Puppet::Functions.create_function(:is_a) do Puppet::Functions.create_function(:is_a) do
# @param value
# The value to be checked
#
# @param type
# The expected type
#
# @return [Boolean]
# Return's `true` or `false`.
dispatch :is_a do dispatch :is_a do
param 'Any', :value param 'Any', :value
param 'Type', :type param 'Type', :type
end end
def is_a(value, type) # rubocop:disable Naming/PredicateName : Used in to many other places to rename at this time, attempting to refactor caused Rubocop to crash. def is_a(value, type) # rubocop:disable Style/PredicateName : Used in to many other places to rename at this time, attempting to refactor caused Rubocop to crash.
# See puppet's lib/puppet/pops/evaluator/evaluator_impl.rb eval_MatchExpression # See puppet's lib/puppet/pops/evaluator/evaluator_impl.rb eval_MatchExpression
Puppet::Pops::Types::TypeCalculator.instance?(type, value) Puppet::Pops::Types::TypeCalculator.instance?(type, value)
end end
......
# frozen_string_literal: true
# @summary
# Wrapper that calls the Puppet 3.x function of the same name.
Puppet::Functions.create_function(:is_absolute_path) do Puppet::Functions.create_function(:is_absolute_path) do
# @param scope
# The main value that will be passed to the wrapped method
#
# @param args
# Any additional values that are to be passed to the wrapped method
#
# @return [Boolea]
# A boolean value returned from the called 3.x function.
dispatch :deprecation_gen do dispatch :deprecation_gen do
param 'Any', :scope param 'Any', :scope
repeated_param 'Any', :args repeated_param 'Any', :args
......
# frozen_string_literal: true
# @summary
# Wrapper that calls the Puppet 3.x function of the same name.
Puppet::Functions.create_function(:is_array) do Puppet::Functions.create_function(:is_array) do
# @param scope
# The main value that will be passed to the wrapped method
#
# @param args
# Any additional values that are to be passed to the wrapped method
#
# @return [Boolea]
# A boolean value returned from the called 3.x function.
dispatch :deprecation_gen do dispatch :deprecation_gen do
param 'Any', :scope param 'Any', :scope
repeated_param 'Any', :args repeated_param 'Any', :args
......
# frozen_string_literal: true
# @summary
# Wrapper that calls the Puppet 3.x function of the same name.
Puppet::Functions.create_function(:is_bool) do Puppet::Functions.create_function(:is_bool) do
# @param scope
# The main value that will be passed to the wrapped method
#
# @param args
# Any additional values that are to be passed to the wrapped method
#
# @return [Boolea]
# A boolean value returned from the called 3.x function.
dispatch :deprecation_gen do dispatch :deprecation_gen do
param 'Any', :scope param 'Any', :scope
repeated_param 'Any', :args repeated_param 'Any', :args
......
# frozen_string_literal: true
# @summary
# Wrapper that calls the Puppet 3.x function of the same name.
Puppet::Functions.create_function(:is_float) do Puppet::Functions.create_function(:is_float) do
# @param scope
# The main value that will be passed to the wrapped method
#
# @param args
# Any additional values that are to be passed to the wrapped method
#
# @return [Boolea]
# A boolean value returned from the called 3.x function.
dispatch :deprecation_gen do dispatch :deprecation_gen do
param 'Any', :scope param 'Any', :scope
repeated_param 'Any', :args repeated_param 'Any', :args
......
# frozen_string_literal: true
# @summary
# Wrapper that calls the Puppet 3.x function of the same name.
Puppet::Functions.create_function(:is_ip_address) do Puppet::Functions.create_function(:is_ip_address) do
# @param scope
# The main value that will be passed to the wrapped method
#
# @param args
# Any additional values that are to be passed to the wrapped method
#
# @return [Boolea]
# A boolean value returned from the called 3.x function.
dispatch :deprecation_gen do dispatch :deprecation_gen do
param 'Any', :scope param 'Any', :scope
repeated_param 'Any', :args repeated_param 'Any', :args
......
This diff is collapsed.