From: Matthaus Owens Date: Tue, 23 Oct 2012 21:13:11 +0000 (-0700) Subject: Add PE facts to stdlib X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=cdf3b05f35f78971203dfd9fadd2552ad5a41bd4;p=puppet-stdlib.git Add PE facts to stdlib As many PE modules have PE specific functionality, but are deployed to all nodes, including FOSS nodes, it is valuable to be able to selectively enable those PE specific functions. These facts allow modules to use the is_pe fact to determine whether the module should be used or not. The facts include is_pe, pe_version, pe_major_version, pe_minor_version, and pe_patch_version. For PE 2.6.0 those facts would have values true, 2.6.0, 2, 6, and 0, respectively. --- diff --git a/lib/facter/pe_version.rb b/lib/facter/pe_version.rb new file mode 100644 index 0000000..7c31e84 --- /dev/null +++ b/lib/facter/pe_version.rb @@ -0,0 +1,47 @@ +# 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 +# +# Resolution: Uses a regex match against puppetversion to determine whether the +# machine has Puppet Enterprise installed, and what version (overall, major, +# minor, patch) is installed. +# +# Caveats: +# +Facter.add("pe_version") do + setcode do + pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/) + pe_ver[1] if pe_ver + end +end + +Facter.add("is_pe") do + setcode do + if Facter.value(:pe_version).to_s.empty? then + false + else + true + end + end +end + +Facter.add("pe_major_version") do + confine :is_pe => true + setcode do + Facter.value(:pe_version).split('.')[0] + end +end + +Facter.add("pe_minor_version") do + confine :is_pe => true + setcode do + Facter.value(:pe_version).split('.')[1] + end +end + +Facter.add("pe_patch_version") do + confine :is_pe => true + setcode do + Facter.value(:pe_version).split('.')[2] + end +end