Skip to content

PE-38219 - Support air gapped installation while using a Windows as Jump host #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/module_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- name: "Run Static & Syntax Tests"
run: |
bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
bundle exec dependency-checker metadata.json --override WhatsARanjit/node_manager,0.7.5
# bundle exec dependency-checker metadata.json --override WhatsARanjit/node_manager,0.7.5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this commented out?



- name: "Run tests"
Expand Down
7 changes: 7 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
* [`infrastatus`](#infrastatus): Runs puppet infra status and returns the output
* [`mkdir_p_file`](#mkdir_p_file): Create a file with the specified content at the specified location
* [`mv`](#mv): Wrapper task for mv command
* [`os_identification`](#os_identification): Return the operating system runnin gon the target as a string
* [`pe_install`](#pe_install): Install Puppet Enterprise from a tarball
* [`pe_ldap_config`](#pe_ldap_config): Set the ldap config in the PE console
* [`pe_uninstall`](#pe_uninstall): Uninstall Puppet Enterprise
Expand Down Expand Up @@ -1242,6 +1243,12 @@ Data type: `String`

New path of file

### <a name="os_identification"></a>`os_identification`

Return the operating system runnin gon the target as a string

**Supports noop?** false

### <a name="pe_install"></a>`pe_install`

Install Puppet Enterprise from a tarball
Expand Down
19 changes: 18 additions & 1 deletion plans/util/retrieve_and_upload.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@
|-HEREDOC
# lint:endignore

$operating_system = run_task('peadm::os_identification', 'local://localhost')
$os_string =$operating_system.first.value['_output']

if 'windows' in $os_string {
$exists = run_command("[System.IO.File]::Exists('${local_path}')", 'local://localhost')
if $exists.first['stdout'].chomp == 'false' {
run_task('peadm::download', 'local://localhost',
source => $source,
path => $local_path,
)
}

$result_size = run_task('peadm::filesize', 'local://localhost',
path => $local_path,
)
$local_size = $result_size.first.value['_output']
} else {
$exists = without_default_logging() || {
run_command("test -e '${local_path}'", 'local://localhost',
_catch_errors => true,
).ok()
}

unless $exists {
run_task('peadm::download', 'local://localhost',
source => $source,
Expand All @@ -45,6 +61,7 @@
$local_size = run_task('peadm::filesize', 'local://localhost',
path => $local_path,
).first['size']
}

$targets_needing_file = run_task('peadm::filesize', $nodes,
path => $upload_path,
Expand Down
1 change: 1 addition & 0 deletions spec/plans/util/retrieve_and_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
include BoltSpec::Plans

it 'file needs downloaded and needs uploaded' do
expect_task('peadm::os_identification')
expect_command("test -e '/tmp/download'").error_with('kind' => 'nope', 'msg' => 'The command failed with exit code 1')
expect_task('peadm::download')
expect_task('peadm::filesize').be_called_times(2).return_for_targets(
Expand Down
6 changes: 3 additions & 3 deletions tasks/download.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"default": "hkp://keyserver.ubuntu.com:80"
}
},
"input_method": "environment",
"implementations": [
{"name": "download.sh"}
]
{"name": "download.sh", "requirements": ["shell"], "input_method": "environment"},
{"name": "download.ps1", "requirements": ["powershell"], "input_method": "powershell"}
]
}
12 changes: 12 additions & 0 deletions tasks/download.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# download.ps1
Param(
$source,
$path
)

try {
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile($source, $path);
}catch {
Write-Host "Installer failed with Exception: $_.Exception.Message"
Exit 1
}
4 changes: 2 additions & 2 deletions tasks/filesize.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"description": "Path to the file to return the size of"
}
},
"input_method": "environment",
"implementations": [
{"name": "filesize.sh"}
{"name": "filesize.sh", "requirements": ["shell"], "input_method": "environment"},
{"name": "filesize.ps1", "requirements": ["powershell"], "input_method": "powershell"}
]
}
28 changes: 28 additions & 0 deletions tasks/filesize.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# filesize.ps1
Param(
$path
)
if ([string]::IsNullOrEmpty($path)){
Write-Host "No path provided to filesize"
Exit 1
}
try {

# Get the File
$File = Get-Item -Path $path
# Get the File Size
$size = $File.Length

# Output a JSON result for ease of Task usage in Puppet Task Plans
if ($size -eq $null) {
Write-Host "{'size': '$null'}"
}else{
Write-Host "{'size': '$size'}"
}

return $size

}catch {
Write-Host "Installer failed with Exception: $_.Exception.Message"
Exit 1
}
9 changes: 9 additions & 0 deletions tasks/os_identification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the whole task required? can't you use https://forge.puppet.com/modules/puppetlabs/facts/readme ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to run factor with operatingsystem but because this is an install some people may not have run puppet agent.
Also $facts or $os_family was not available on windows jump host

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task works fine without facter/puppet. They don't need to be installed. That's why I suggested it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should be addressed before merging.

"description": "Return the operating system runnin gon the target as a string",
"parameters": { },
"implementations": [
{"name": "os_identification.sh", "requirements": ["shell"], "input_method": "environment"},
{"name": "os_identification.ps1", "requirements": ["powershell"]}
]
}

18 changes: 18 additions & 0 deletions tasks/os_identification.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# os_identification.ps1
try {

$os = [System.Environment]::OSVersion.Platform

if ($os -eq "Win32NT") {
$osfamily = "windows"
}elseif ($os -eq "Unix") {
$osfamily = "unix"
}else {
$osfamily = "unknown"
}

return $osfamily
}catch {
Write-Host "Installer failed with Exception: $_.Exception.Message"
Exit 1
}
18 changes: 18 additions & 0 deletions tasks/os_identification.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
osfamily="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
osfamily="macOS"
elif [[ "$OSTYPE" == "cygwin" ]]; then
osfamily="cygwin"
elif [[ "$OSTYPE" == "msys" ]]; then
osfamily="msys"
elif [[ "$OSTYPE" == "win32" ]]; then
osfamily="windows"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
osfamily="freebsd"
else
osfamily="unknown"
fi

echo $osfamily

Loading