|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | # Puppet Agent task helper |
4 | | -module PuppetAgent::RbTaskHelper |
5 | | - private |
6 | | - |
7 | | - def error_result(error_type, error_message) |
8 | | - { |
9 | | - '_error' => { |
10 | | - 'msg' => error_message, |
11 | | - 'kind' => error_type, |
12 | | - 'details' => {}, |
13 | | - }, |
14 | | - } |
15 | | - end |
16 | | - |
17 | | - def puppet_bin_present? |
18 | | - File.exist?(puppet_bin) |
19 | | - end |
20 | | - |
21 | | - # Returns the path to the Puppet agent executable |
22 | | - def puppet_bin |
23 | | - @puppet_bin ||= if Puppet.features.microsoft_windows? |
24 | | - puppet_bin_windows |
25 | | - else |
26 | | - '/opt/puppetlabs/bin/puppet' |
27 | | - end |
28 | | - end |
29 | | - |
30 | | - # Returns the path to the Puppet agent executable on Windows |
31 | | - def puppet_bin_windows |
32 | | - require 'win32/registry' |
33 | | - |
34 | | - install_dir = begin |
35 | | - Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg| |
36 | | - # Rescue missing key |
37 | | - dir = begin |
38 | | - reg['RememberedInstallDir64'] |
39 | | - rescue StandardError |
40 | | - '' |
41 | | - end |
42 | | - # Both keys may exist, make sure the dir exists |
43 | | - break dir if File.exist?(dir) |
44 | | - |
45 | | - # Rescue missing key |
46 | | - begin |
47 | | - reg['RememberedInstallDir'] |
48 | | - rescue StandardError |
49 | | - '' |
| 4 | +module PuppetAgent |
| 5 | + # Puppet Agent Ruby task helper |
| 6 | + module RbTaskHelper |
| 7 | + private |
| 8 | + |
| 9 | + def error_result(error_type, error_message) |
| 10 | + { |
| 11 | + '_error' => { |
| 12 | + 'msg' => error_message, |
| 13 | + 'kind' => error_type, |
| 14 | + 'details' => {}, |
| 15 | + }, |
| 16 | + } |
| 17 | + end |
| 18 | + |
| 19 | + def puppet_bin_present? |
| 20 | + File.exist?(puppet_bin) |
| 21 | + end |
| 22 | + |
| 23 | + # Returns the path to the Puppet agent executable |
| 24 | + def puppet_bin |
| 25 | + @puppet_bin ||= if Puppet.features.microsoft_windows? |
| 26 | + puppet_bin_windows |
| 27 | + else |
| 28 | + '/opt/puppetlabs/bin/puppet' |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + # Returns the path to the Puppet agent executable on Windows |
| 33 | + def puppet_bin_windows |
| 34 | + require 'win32/registry' |
| 35 | + |
| 36 | + install_dir = begin |
| 37 | + Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Puppet Labs\Puppet') do |reg| |
| 38 | + # Rescue missing key |
| 39 | + dir = begin |
| 40 | + reg['RememberedInstallDir64'] |
| 41 | + rescue StandardError |
| 42 | + '' |
| 43 | + end |
| 44 | + # Both keys may exist, make sure the dir exists |
| 45 | + break dir if File.exist?(dir) |
| 46 | + |
| 47 | + # Rescue missing key |
| 48 | + begin |
| 49 | + reg['RememberedInstallDir'] |
| 50 | + rescue StandardError |
| 51 | + '' |
| 52 | + end |
50 | 53 | end |
| 54 | + rescue Win32::Registry::Error |
| 55 | + # Rescue missing registry path |
| 56 | + '' |
51 | 57 | end |
52 | | - rescue Win32::Registry::Error |
53 | | - # Rescue missing registry path |
54 | | - '' |
55 | | - end |
56 | 58 |
|
57 | | - File.join(install_dir, 'bin', 'puppet.bat') |
| 59 | + File.join(install_dir, 'bin', 'puppet.bat') |
| 60 | + end |
58 | 61 | end |
59 | 62 | end |
0 commit comments