diff options
author | Jeff McCune <jeff@puppetlabs.com> | 2012-10-25 10:30:14 -0700 |
---|---|---|
committer | Jeff McCune <jeff@puppetlabs.com> | 2012-10-25 10:30:14 -0700 |
commit | b8a0f2817279246224dce146a7fb31d14cee4ea5 (patch) | |
tree | 74a524a17c155fa98ced1e592b07e7389451c49b /lib/facter/pe_version.rb | |
parent | 6961179007dce76d7fb9bd1fc361273acb4129a7 (diff) | |
parent | 74e6411157b8df1af9a24c17971e3236f3096529 (diff) |
Merge branch '2.4.x'
* 2.4.x:
Prevent undefined method `split' for nil:NilClass with pe_foo_version facts
(maint) Clear all facts before each example
Add spec tests for pe_version facts
Add PE facts to stdlib
Conflicts:
spec/spec_helper.rb
Diffstat (limited to 'lib/facter/pe_version.rb')
-rw-r--r-- | lib/facter/pe_version.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/facter/pe_version.rb b/lib/facter/pe_version.rb new file mode 100644 index 0000000..0cc0f64 --- /dev/null +++ b/lib/facter/pe_version.rb @@ -0,0 +1,53 @@ +# 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 + if pe_version = Facter.value(:pe_version) + pe_version.to_s.split('.')[0] + end + end +end + +Facter.add("pe_minor_version") do + confine :is_pe => true + setcode do + if pe_version = Facter.value(:pe_version) + pe_version.to_s.split('.')[1] + end + end +end + +Facter.add("pe_patch_version") do + confine :is_pe => true + setcode do + if pe_version = Facter.value(:pe_version) + pe_version.to_s.split('.')[2] + end + end +end |