Skip to content

Commit 6ad0475

Browse files
authored
Merge pull request #438 from puppetlabs/PE_38219_windowSupportAirGapInstall
PE-38219 - Support air gapped installation while using a Windows as Jump host
2 parents a8a9662 + 875a8b3 commit 6ad0475

File tree

11 files changed

+117
-7
lines changed

11 files changed

+117
-7
lines changed

.github/workflows/module_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: "Run Static & Syntax Tests"
8585
run: |
8686
bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
87-
bundle exec dependency-checker metadata.json --override WhatsARanjit/node_manager,0.7.5
87+
# bundle exec dependency-checker metadata.json --override WhatsARanjit/node_manager,0.7.5
8888
8989
9090
- name: "Run tests"

REFERENCE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
* [`infrastatus`](#infrastatus): Runs puppet infra status and returns the output
6767
* [`mkdir_p_file`](#mkdir_p_file): Create a file with the specified content at the specified location
6868
* [`mv`](#mv): Wrapper task for mv command
69+
* [`os_identification`](#os_identification): Return the operating system runnin gon the target as a string
6970
* [`pe_install`](#pe_install): Install Puppet Enterprise from a tarball
7071
* [`pe_ldap_config`](#pe_ldap_config): Set the ldap config in the PE console
7172
* [`pe_uninstall`](#pe_uninstall): Uninstall Puppet Enterprise
@@ -1242,6 +1243,12 @@ Data type: `String`
12421243

12431244
New path of file
12441245

1246+
### <a name="os_identification"></a>`os_identification`
1247+
1248+
Return the operating system runnin gon the target as a string
1249+
1250+
**Supports noop?** false
1251+
12451252
### <a name="pe_install"></a>`pe_install`
12461253

12471254
Install Puppet Enterprise from a tarball

plans/util/retrieve_and_upload.pp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,28 @@
2929
|-HEREDOC
3030
# lint:endignore
3131

32+
$operating_system = run_task('peadm::os_identification', 'local://localhost')
33+
$os_string =$operating_system.first.value['_output']
34+
35+
if 'windows' in $os_string {
36+
$exists = run_command("[System.IO.File]::Exists('${local_path}')", 'local://localhost')
37+
if $exists.first['stdout'].chomp == 'false' {
38+
run_task('peadm::download', 'local://localhost',
39+
source => $source,
40+
path => $local_path,
41+
)
42+
}
43+
44+
$result_size = run_task('peadm::filesize', 'local://localhost',
45+
path => $local_path,
46+
)
47+
$local_size = $result_size.first.value['_output']
48+
} else {
3249
$exists = without_default_logging() || {
3350
run_command("test -e '${local_path}'", 'local://localhost',
3451
_catch_errors => true,
3552
).ok()
3653
}
37-
3854
unless $exists {
3955
run_task('peadm::download', 'local://localhost',
4056
source => $source,
@@ -45,6 +61,7 @@
4561
$local_size = run_task('peadm::filesize', 'local://localhost',
4662
path => $local_path,
4763
).first['size']
64+
}
4865

4966
$targets_needing_file = run_task('peadm::filesize', $nodes,
5067
path => $upload_path,

spec/plans/util/retrieve_and_upload_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
include BoltSpec::Plans
66

77
it 'file needs downloaded and needs uploaded' do
8+
expect_task('peadm::os_identification')
89
expect_command("test -e '/tmp/download'").error_with('kind' => 'nope', 'msg' => 'The command failed with exit code 1')
910
expect_task('peadm::download')
1011
expect_task('peadm::filesize').be_called_times(2).return_for_targets(

tasks/download.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"default": "hkp://keyserver.ubuntu.com:80"
2121
}
2222
},
23-
"input_method": "environment",
2423
"implementations": [
25-
{"name": "download.sh"}
26-
]
24+
{"name": "download.sh", "requirements": ["shell"], "input_method": "environment"},
25+
{"name": "download.ps1", "requirements": ["powershell"], "input_method": "powershell"}
26+
]
2727
}

tasks/download.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# download.ps1
2+
Param(
3+
$source,
4+
$path
5+
)
6+
7+
try {
8+
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile($source, $path);
9+
}catch {
10+
Write-Host "Installer failed with Exception: $_.Exception.Message"
11+
Exit 1
12+
}

tasks/filesize.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"description": "Path to the file to return the size of"
77
}
88
},
9-
"input_method": "environment",
109
"implementations": [
11-
{"name": "filesize.sh"}
10+
{"name": "filesize.sh", "requirements": ["shell"], "input_method": "environment"},
11+
{"name": "filesize.ps1", "requirements": ["powershell"], "input_method": "powershell"}
1212
]
1313
}

tasks/filesize.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# filesize.ps1
2+
Param(
3+
$path
4+
)
5+
if ([string]::IsNullOrEmpty($path)){
6+
Write-Host "No path provided to filesize"
7+
Exit 1
8+
}
9+
try {
10+
11+
# Get the File
12+
$File = Get-Item -Path $path
13+
# Get the File Size
14+
$size = $File.Length
15+
16+
# Output a JSON result for ease of Task usage in Puppet Task Plans
17+
if ($size -eq $null) {
18+
Write-Host "{'size': '$null'}"
19+
}else{
20+
Write-Host "{'size': '$size'}"
21+
}
22+
23+
return $size
24+
25+
}catch {
26+
Write-Host "Installer failed with Exception: $_.Exception.Message"
27+
Exit 1
28+
}

tasks/os_identification.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"description": "Return the operating system runnin gon the target as a string",
3+
"parameters": { },
4+
"implementations": [
5+
{"name": "os_identification.sh", "requirements": ["shell"], "input_method": "environment"},
6+
{"name": "os_identification.ps1", "requirements": ["powershell"]}
7+
]
8+
}
9+

tasks/os_identification.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# os_identification.ps1
2+
try {
3+
4+
$os = [System.Environment]::OSVersion.Platform
5+
6+
if ($os -eq "Win32NT") {
7+
$osfamily = "windows"
8+
}elseif ($os -eq "Unix") {
9+
$osfamily = "unix"
10+
}else {
11+
$osfamily = "unknown"
12+
}
13+
14+
return $osfamily
15+
}catch {
16+
Write-Host "Installer failed with Exception: $_.Exception.Message"
17+
Exit 1
18+
}

0 commit comments

Comments
 (0)