Skip to content

Commit

Permalink
Add PE facts to stdlib
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haus committed Oct 24, 2012
1 parent 417d219 commit 220a7a3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions 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

0 comments on commit 220a7a3

Please sign in to comment.