|
1 | 1 | require 'puppet/provider/package'
|
2 | 2 | require 'json'
|
3 | 3 |
|
4 |
| -Puppet::Type.type(:package).provide :psmodule, parent: Puppet::Provider::Package do |
5 |
| - confine operatingsystem: :windows |
6 |
| - confine feature: :powershellget |
7 |
| - |
8 |
| - has_feature :installable |
9 |
| - has_feature :uninstallable |
10 |
| - has_feature :upgradeable |
11 |
| - has_feature :versionable |
12 |
| - |
13 |
| - commands powershell: |
14 |
| - if File.exist?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe") |
15 |
| - "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe" |
16 |
| - elsif File.exist?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") |
17 |
| - "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" |
18 |
| - else |
19 |
| - 'powershell.exe' |
20 |
| - end |
| 4 | +Puppet::Type.type(:package).provide :powershellcore, parent: Puppet::Provider::Package do |
| 5 | + initvars |
| 6 | + has_feature :installable, :uninstallable, :upgradeable, :versionable |
| 7 | + commands pwsh: 'pwsh' |
21 | 8 |
|
22 | 9 | def self.invoke_ps_command(command)
|
23 |
| - result = powershell(['-noprofile', '-executionpolicy', 'bypass', '-command', command]) |
| 10 | + result = pwsh(['-NoProfile', '-NonInteractive', '-NoLogo', '-Command', "$ProgressPreference = 'SilentlyContinue'; #{command}"]) |
| 11 | + Puppet.debug result.exitstatus |
| 12 | + Puppet.debug result.lines |
24 | 13 | result.lines
|
25 | 14 | end
|
26 | 15 |
|
@@ -62,29 +51,29 @@ def self.instances_command
|
62 | 51 | [ordered]@{
|
63 | 52 | 'name' = $_.Name
|
64 | 53 | 'ensure' = @(($_.Group).Version)
|
65 |
| - 'provider' = 'psmodule' |
| 54 | + 'provider' = '#{name}' |
66 | 55 | } | ConvertTo-Json -Depth 99 -Compress
|
67 | 56 | }
|
68 | 57 | COMMAND
|
69 | 58 | end
|
70 | 59 |
|
71 | 60 | def install_command
|
72 |
| - command = "Install-Module #{@resource[:name]} -Force" |
| 61 | + command = "Install-Module #{@resource[:name]} -Scope AllUsers -Force" |
73 | 62 | command << " -RequiredVersion #{@resource[:ensure]}" unless [:present, :latest].include? @resource[:ensure]
|
74 | 63 | command << " -Repository #{@resource[:source]}" if @resource[:source]
|
75 | 64 | command
|
76 | 65 | end
|
77 | 66 |
|
78 | 67 | def uninstall_command
|
79 |
| - "Uninstall-Module #{@resource[:name]} -AllVersions -Force" |
| 68 | + "Uninstall-Module #{@resource[:name]} -AllVersions -Scope AllUsers -Force" |
80 | 69 | end
|
81 | 70 |
|
82 | 71 | def latest_command
|
83 | 72 | "$mod = Find-Module #{@resource[:name]}; $mod.Version.ToString()"
|
84 | 73 | end
|
85 | 74 |
|
86 | 75 | def update_command
|
87 |
| - command = "Install-Module #{@resource[:name]} -Force" |
| 76 | + command = "Install-Module #{@resource[:name]} -Scope AllUsers -Force" |
88 | 77 | command << " -Repository #{@resource[:source]}" if @resource[:source]
|
89 | 78 | command
|
90 | 79 | end
|
|
0 commit comments