Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / facter / pe_version.rb
1 # Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version
2 #
3 # Purpose: Return various facts about the PE state of the system
4 #
5 # Resolution: Uses a regex match against puppetversion to determine whether the
6 #   machine has Puppet Enterprise installed, and what version (overall, major,
7 #   minor, patch) is installed.
8 #
9 # Caveats:
10 #
11 Facter.add("pe_version") do
12   setcode do
13     puppet_ver = Facter.value("puppetversion")
14     if puppet_ver != nil
15       pe_ver = puppet_ver.match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
16       pe_ver[1] if pe_ver
17     else
18       nil
19     end
20   end
21 end
22
23 Facter.add("is_pe") do
24   setcode do
25     if Facter.value(:pe_version).to_s.empty? then
26       false
27     else
28       true
29     end
30   end
31 end
32
33 Facter.add("pe_major_version") do
34   confine :is_pe => true
35   setcode do
36     if pe_version = Facter.value(:pe_version)
37       pe_version.to_s.split('.')[0]
38     end
39   end
40 end
41
42 Facter.add("pe_minor_version") do
43   confine :is_pe => true
44   setcode do
45     if pe_version = Facter.value(:pe_version)
46       pe_version.to_s.split('.')[1]
47     end
48   end
49 end
50
51 Facter.add("pe_patch_version") do
52   confine :is_pe => true
53   setcode do
54     if pe_version = Facter.value(:pe_version)
55       pe_version.to_s.split('.')[2]
56     end
57   end
58 end