|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -module PuppetAgent |
4 |
| - module 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 |
| - '' |
50 |
| - end |
| 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 | + '' |
51 | 50 | end
|
52 |
| - rescue Win32::Registry::Error |
53 |
| - # Rescue missing registry path |
54 |
| - '' |
55 | 51 | end
|
| 52 | + rescue Win32::Registry::Error |
| 53 | + # Rescue missing registry path |
| 54 | + '' |
| 55 | + end |
56 | 56 |
|
57 |
| - File.join(install_dir, 'bin', 'puppet.bat') |
58 |
| - end |
| 57 | + File.join(install_dir, 'bin', 'puppet.bat') |
59 | 58 | end
|
60 | 59 | end
|
0 commit comments