# frozen_string_literal: true
# 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
......@@ -10,24 +8,18 @@
#
# Caveats:
#
# Fact: pe_version
Facter.add('pe_version') do
setcode do
found_version = Facter.value('pe_build')
unless found_version
puppet_ver = Facter.value('puppetversion')
unless puppet_ver.nil?
pe_ver = puppet_ver.match(%r{Puppet Enterprise (\d+\.\d+\.\d+)})
found_version = pe_ver[1] if pe_ver
end
puppet_ver = Facter.value('puppetversion')
if !puppet_ver.nil?
pe_ver = puppet_ver.match(%r{Puppet Enterprise (\d+\.\d+\.\d+)})
pe_ver[1] if pe_ver
else
nil
end
found_version
end
end
# Fact: is_pe
Facter.add('is_pe') do
setcode do
if Facter.value(:pe_version).to_s.empty?
......@@ -38,9 +30,8 @@ Facter.add('is_pe') do
end
end
# Fact: pe_major_version
Facter.add('pe_major_version') do
confine is_pe: true
confine :is_pe => true
setcode do
pe_version = Facter.value(:pe_version)
if pe_version
......@@ -49,9 +40,8 @@ Facter.add('pe_major_version') do
end
end
# Fact: pe_minor_version
Facter.add('pe_minor_version') do
confine is_pe: true
confine :is_pe => true
setcode do
pe_version = Facter.value(:pe_version)
if pe_version
......@@ -60,9 +50,8 @@ Facter.add('pe_minor_version') do
end
end
# Fact: pe_patch_version
Facter.add('pe_patch_version') do
confine is_pe: true
confine :is_pe => true
setcode do
pe_version = Facter.value(:pe_version)
if pe_version
......
# frozen_string_literal: true
# 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
# 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.
#
# The values should be directly usable in a File resource path attribute.
......@@ -18,7 +16,7 @@ rescue LoadError => e
load rb_file if File.exist?(rb_file) || raise(e)
end
# Facter fact returns the value of the Puppet vardir
# These will be nil if Puppet is not available.
Facter.add(:puppet_vardir) do
setcode do
Facter::Util::PuppetSettings.with_puppet do
......@@ -27,7 +25,6 @@ Facter.add(:puppet_vardir) do
end
end
# Facter fact returns the value of the Puppet environment path
Facter.add(:puppet_environmentpath) do
setcode do
Facter::Util::PuppetSettings.with_puppet do
......@@ -36,7 +33,6 @@ Facter.add(:puppet_environmentpath) do
end
end
# Facter fact returns the value of the Puppet server
Facter.add(:puppet_server) do
setcode do
Facter::Util::PuppetSettings.with_puppet do
......
# frozen_string_literal: true
# root_home.rb
# A facter fact to determine the root home directory.
# This varies on PE supported platforms and may be
# reconfigured by the end user.
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
# determines the root home directory
def returnt_root_home
root_ent = Facter::Util::Resolution.exec('getent passwd root')
# The home directory is the sixth element in the passwd entry
# If the platform doesn't have getent, root_ent will be nil and we should
# return it straight away.
root_ent && root_ent.split(':')[5]
end
def returnt_root_home
root_ent = Facter::Util::Resolution.exec('getent passwd root')
# The home directory is the sixth element in the passwd entry
# If the platform doesn't have getent, root_ent will be nil and we should
# return it straight away.
root_ent && root_ent.split(':')[5]
end
end
end
......@@ -23,7 +18,7 @@ Facter.add(:root_home) do
end
Facter.add(:root_home) do
confine kernel: :darwin
confine :kernel => :darwin
setcode do
str = Facter::Util::Resolution.exec('dscacheutil -q user -a name root')
hash = {}
......@@ -36,12 +31,12 @@ Facter.add(:root_home) do
end
Facter.add(:root_home) do
confine kernel: :aix
confine :kernel => :aix
root_home = nil
setcode do
str = Facter::Util::Resolution.exec('lsuser -c -a home root')
str&.split("\n")&.each do |line|
next if %r{^#}.match?(line)
str && str.split("\n").each do |line|
next if line =~ %r{^#}
root_home = line.split(%r{:})[1]
end
root_home
......
# frozen_string_literal: true
# Fact: service_provider
#
# Purpose: Returns the default provider Puppet will choose to manage services
......@@ -14,6 +12,6 @@ require 'puppet/type/service'
Facter.add(:service_provider) 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
# frozen_string_literal: true
# A method to evaluate a Facter code block if puppet is loaded.
module Facter::Util::PuppetSettings
# 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.
# 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.
# 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.
# 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
# @param key
# @param message
# @return deprecated warnings
dispatch :deprecation do
param 'String', :key
param 'String', :message
......@@ -27,7 +19,7 @@ Puppet::Functions.create_function(:deprecation) do
end
# depending on configuration setting of strict
case Puppet.settings[:strict]
when :off
when :off # rubocop:disable Lint/EmptyWhen : Is required to prevent false errors
# do nothing
when :error
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
# does not exist, returns Undef.
# Example usage:
#
# @example Example usage:
# fact('osfamily')
# fact('os.architecture')
#
# @example Array indexing:
# Array indexing:
#
# fact('mountpoints."/dev".options.1')
#
# @example Fact containing a "." in the name:
# Fact containing a "." in the name:
#
# fact('vmware."VRA.version"')
#
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
param 'String', :fact_name
end
......
# frozen_string_literal: true
# @summary
# Boolean check to determine whether a variable is of a given data type.
# This is equivalent to the `=~` type checks.
# 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
# foo = 3
# $bar = [1,2,3]
# $baz = 'A string!'
# foo = 3
# $bar = [1,2,3]
# $baz = 'A string!'
#
# if $foo.is_a(Integer) {
# notify { 'foo!': }
# }
# if $bar.is_a(Array) {
# notify { 'bar!': }
# }
# if $baz.is_a(String) {
# notify { 'baz!': }
# }
# if $foo.is_a(Integer) {
# notify { 'foo!': }
# }
# if $bar.is_a(Array) {
# notify { 'bar!': }
# }
# if $baz.is_a(String) {
# notify { 'baz!': }
# }
#
# See the documentation for "The Puppet Type System" for more information about types.
# See the `assert_type()` function for flexible ways to assert the type of a value.
#
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
param 'Any', :value
param 'Type', :type
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
Puppet::Pops::Types::TypeCalculator.instance?(type, value)
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
# @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
param 'Any', :scope
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
# @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
param 'Any', :scope
repeated_param 'Any', :args
......
This diff is collapsed.