From 220a7a34c77ee0ea015529ea75a88b77dad8f187 Mon Sep 17 00:00:00 2001 From: Matthaus Owens Date: Tue, 23 Oct 2012 14:13:11 -0700 Subject: [PATCH] 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. --- lib/facter/pe_version.rb | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/facter/pe_version.rb diff --git a/lib/facter/pe_version.rb b/lib/facter/pe_version.rb new file mode 100644 index 000000000..5632b0936 --- /dev/null +++ b/lib/facter/pe_version.rb @@ -0,0 +1,43 @@ +# 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 + not Facter.value("pe_version").nil? and not Facter.value("pe_version").empty? + 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