Skip to content

Commit 66ea17d

Browse files
committed
fix powershellcore install issues
1 parent dc10b06 commit 66ea17d

File tree

8 files changed

+97
-28
lines changed

8 files changed

+97
-28
lines changed

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Metrics/BlockLength:
1414
Max: 50
1515

1616
Metrics/LineLength:
17-
Max: 130
17+
Max: 135
1818

1919
EndOfLine:
2020
Enabled: false

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gem 'metadata-json-lint'
66
gem 'puppet', puppetversion
77
gem 'puppet-lint', '>= 1.0.0'
88
gem 'puppetlabs_spec_helper', '>= 1.0.0'
9+
gem 'semantic_puppet', '>= 1.0.0'
910

1011
# rspec must be v2 for ruby 1.8.7
1112
if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9'

README.md

+32-8
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,60 @@
1111

1212
## Description
1313

14-
This module adds a new type and provider for registering PowerShell repositories
15-
and a new package provider for installing PowerShell modules.
14+
This module allows PowerShell repositories to be registered as package sources
15+
and PowerShell modules to be installed using the Puppet Package type.
16+
17+
The module supports Windows PowerShell (PowerShell 5) and PowerShell Core (PowerShell 6)
1618

1719
## Setup
1820

1921
### Setup Requirements
2022

21-
The PowerShellGet PowerShell module must be installed as well as the NuGet package
22-
provider. PowerShellGet is included with WMF5 or can be installed for earlier
23+
For Windows PowerShell the PowerShellGet PowerShell module must be installed as well as
24+
the NuGet package provider. PowerShellGet is included with WMF5 or can be installed for earlier
2325
versions here http://go.microsoft.com/fwlink/?LinkID=746217&clcid=0x409
26+
2427
NuGet can be installed by running
25-
Install-PackageProvider Nuget –Force
2628

27-
### Beginning with powershellmodule
29+
`Install-PackageProvider Nuget –Force`
2830

2931
## Usage
3032

33+
### Windows PowerShell
34+
35+
~~~ puppet
36+
psrepository { 'my-internal-repo':
37+
ensure => present,
38+
source_location => 'http://myrepo.corp.com/api/nuget/powershell',
39+
installation_policy => 'trusted',
40+
provider => 'windowspowershell',
41+
}
42+
~~~
43+
44+
~~~ puppet
45+
package { 'Pester':
46+
ensure => '4.0.3',
47+
source => 'PSGallery',
48+
provider => 'windowspowershell',
49+
}
50+
~~~
51+
52+
### PowerShell Core
53+
3154
~~~ puppet
3255
psrepository { 'my-internal-repo':
3356
ensure => present,
3457
source_location => 'http://myrepo.corp.com/api/nuget/powershell',
3558
installation_policy => 'trusted',
59+
provider => 'powershellcore',
3660
}
3761
~~~
3862

3963
~~~ puppet
40-
package { 'pester':
64+
package { 'Pester':
4165
ensure => '4.0.3',
4266
source => 'PSGallery',
43-
provider => 'psmodule',
67+
provider => 'powershellcore',
4468
}
4569
~~~
4670

lib/puppet/feature/powershellgetcore.rb

-7
This file was deleted.

lib/puppet/provider/package/powershellcore.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
commands pwsh: 'pwsh'
88

99
def self.invoke_ps_command(command)
10+
# override_locale is necessary otherwise the Install-Module commands silently fails on Linux
1011
result = Puppet::Util::Execution.execute(['pwsh', '-NoProfile', '-NonInteractive', '-NoLogo', '-Command',
1112
"$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; #{command}"],
1213
override_locale: false)
@@ -59,13 +60,13 @@ def self.instances_command
5960

6061
def install_command
6162
command = "Install-Module #{@resource[:name]} -Scope AllUsers -Force"
62-
command << " -RequiredVersion #{@resource[:ensure]}" unless [:present, :latest].include? @resource[:ensure]
63+
command << " -RequiredVersion #{@resource[:ensure]}" unless %i[present latest].include? @resource[:ensure]
6364
command << " -Repository #{@resource[:source]}" if @resource[:source]
6465
command
6566
end
6667

6768
def uninstall_command
68-
"Uninstall-Module #{@resource[:name]} -AllVersions -Scope AllUsers -Force"
69+
"Uninstall-Module #{@resource[:name]} -AllVersions -Force"
6970
end
7071

7172
def latest_command

lib/puppet/provider/package/windowspowershell.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
commands powershell: 'powershell'
66

77
def self.invoke_ps_command(command)
8-
result = powershell(['-noprofile', '-executionpolicy', 'bypass', '-command', command])
8+
result = powershell(['-NoProfile', '-ExecutionPolicy', 'Bypass', '-NonInteractive', '-NoLogo', '-Command',
9+
"$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; #{command}"])
910
result.lines
1011
end
1112
end

metadata.json

+53-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"name": "hbuckle-powershellmodule",
3-
"version": "0.2.0",
3+
"version": "1.0.0",
44
"author": "Henry Buckle",
55
"summary": "Manage PowerShell modules and repositories",
66
"license": "Apache-2.0",
77
"source": "https://github.com/hbuckle/puppet-powershellmodule",
88
"project_page": "https://github.com/hbuckle/puppet-powershellmodule",
99
"issues_url": "https://github.com/hbuckle/puppet-powershellmodule/issues",
10-
"tags": ["powershell", "microsoft", "package"],
10+
"tags": [
11+
"powershell",
12+
"microsoft",
13+
"package"
14+
],
1115
"dependencies": [],
1216
"operatingsystem_support": [
1317
{
@@ -22,7 +26,52 @@
2226
"8.1",
2327
"10"
2428
]
29+
},
30+
{
31+
"operatingsystem": "Debian",
32+
"operatingsystemrelease": [
33+
"8.7+",
34+
"9"
35+
]
36+
},
37+
{
38+
"operatingsystem": "CentOS",
39+
"operatingsystemrelease": [
40+
"7"
41+
]
42+
},
43+
{
44+
"operatingsystem": "Ubuntu",
45+
"operatingsystemrelease": [
46+
"14.04",
47+
"16.04",
48+
"17.04"
49+
]
50+
},
51+
{
52+
"operatingsystem": "RedHat",
53+
"operatingsystemrelease": [
54+
"7"
55+
]
56+
},
57+
{
58+
"operatingsystem": "Fedora",
59+
"operatingsystemrelease": [
60+
"25",
61+
"26"
62+
]
63+
},
64+
{
65+
"operatingsystem": "OpenSUSE",
66+
"operatingsystemrelease": [
67+
"42.2"
68+
]
69+
},
70+
{
71+
"operatingsystem": "osx",
72+
"operatingsystemrelease": [
73+
"10.12+"
74+
]
2575
}
2676
]
27-
}
28-
77+
}

spec/unit/puppet/provider/psrepository_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
provider_class.instances_command
1515
).and_return(
1616
[
17-
'{"name":"Repo1","source_location":"https://repo1.com","installation_policy":"untrusted"}',
18-
'{"name":"Repo2","source_location":"https://repo2.com","installation_policy":"trusted"}'
17+
'{"name":"Repo1","source_location":"https://repo1.com","installation_policy":"untrusted","provider":"windowspowershell"}',
18+
'{"name":"Repo2","source_location":"https://repo2.com","installation_policy":"trusted","provider":"windowspowershell"}'
1919
]
2020
)
2121
end
2222
describe :instances do
23-
specify 'returns an array of :windows providers' do
23+
specify 'returns an array of :windowspowershell providers' do
2424
instances = provider_class.instances
2525
expect(instances.count).to eq(2)
2626
expect(instances).to all(be_instance_of(provider_class))
@@ -29,11 +29,11 @@
2929
instances = provider_class.instances
3030
expect(instances[0].instance_variable_get('@property_hash')).to eq(
3131
name: 'Repo1', ensure: :present, source_location: 'https://repo1.com',
32-
installation_policy: 'untrusted'
32+
installation_policy: 'untrusted', provider: 'windowspowershell'
3333
)
3434
expect(instances[1].instance_variable_get('@property_hash')).to eq(
3535
name: 'Repo2', ensure: :present, source_location: 'https://repo2.com',
36-
installation_policy: 'trusted'
36+
installation_policy: 'trusted', provider: 'windowspowershell'
3737
)
3838
end
3939
end

0 commit comments

Comments
 (0)