diff options
author | Matthaus Owens <matthaus@puppetlabs.com> | 2012-10-23 14:13:11 -0700 |
---|---|---|
committer | Matthaus Owens <matthaus@puppetlabs.com> | 2012-10-24 17:23:42 -0700 |
commit | cdf3b05f35f78971203dfd9fadd2552ad5a41bd4 (patch) | |
tree | b1c1f5c24b8a66c2eb97fdfa8b0d32c9bde165cb /lib | |
parent | 417d219aa6e42f2a16af42c98aa063fc1d9d2ecd (diff) |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/pe_version.rb | 47 |
1 files changed, 47 insertions, 0 deletions
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 |