-
Notifications
You must be signed in to change notification settings - Fork 194
Update module to support puppetcore on Windows #766
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,28 @@ | |
# for installation. This is used on platforms without package managers capable of | ||
# working with a remote https repository. | ||
# | ||
# @param source | ||
# The source file for the puppet-agent package. Can use any of the data types | ||
# and protocols that the File resource's source attribute can. | ||
# @api private | ||
class puppet_agent::prepare::package ( | ||
Variant[String, Array] $source, | ||
Optional[String[1]] $destination_name = undef | ||
) { | ||
assert_private() | ||
|
||
file { $puppet_agent::params::local_packages_dir: | ||
ensure => directory, | ||
} | ||
|
||
# In order for the 'basename' function to work correctly we need to change | ||
# any \s to /s (even for windows UNC paths) so that it will correctly pull off | ||
# the filename. Since this operation is only grabbing the base filename and not | ||
# any part of the path this should be safe, since the source will simply remain | ||
# what it was before and we can still pull off the filename. | ||
$package_file_name = basename(regsubst($source, "\\\\", '/', 'G')) | ||
$package_file_name = if $destination_name { | ||
$destination_name | ||
} else { | ||
# In order for the 'basename' function to work correctly we need to change | ||
# any \s to /s (even for windows UNC paths) so that it will correctly pull off | ||
# the filename. Since this operation is only grabbing the base filename and not | ||
# any part of the path this should be safe, since the source will simply remain | ||
# what it was before and we can still pull off the filename. | ||
basename(regsubst($source, "\\\\", '/', 'G')) | ||
} | ||
|
||
if $facts['os']['family'] =~ /windows/ { | ||
$local_package_file_path = windows_native_path("${puppet_agent::params::local_packages_dir}/${package_file_name}") | ||
$mode = undef | ||
|
@@ -28,12 +32,38 @@ | |
$mode = '0644' | ||
} | ||
|
||
file { $local_package_file_path: | ||
ensure => file, | ||
owner => $puppet_agent::params::user, | ||
group => $puppet_agent::params::group, | ||
mode => $mode, | ||
source => $source, | ||
require => File[$puppet_agent::params::local_packages_dir], | ||
if $puppet_agent::collection =~ /core/ and $facts['os']['family'] =~ /windows/ { | ||
joshcooper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$download_username = getvar('puppet_agent::username', 'forge-key') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you use getvar, instead of accessing the variable directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was mainly following the |
||
$download_password = unwrap(getvar('puppet_agent::password')) | ||
$dev = count(split($puppet_agent::prepare::package_version, '\.')) > 3 | ||
|
||
$_download_puppet = windows_native_path("${facts['env_temp_variable']}/download_puppet.ps1") | ||
file { $_download_puppet: | ||
ensure => file, | ||
content => Sensitive(epp('puppet_agent/download_puppet.ps1.epp')), | ||
} | ||
|
||
exec { 'Download Puppet Agent': | ||
command => [ | ||
"${facts['os']['windows']['system32']}\\WindowsPowerShell\\v1.0\\powershell.exe", | ||
'-ExecutionPolicy', | ||
'Bypass', | ||
'-NoProfile', | ||
'-NoLogo', | ||
'-NonInteractive', | ||
$_download_puppet | ||
], | ||
creates => $local_package_file_path, | ||
require => File[$puppet_agent::params::local_packages_dir], | ||
} | ||
} else { | ||
file { $local_package_file_path: | ||
ensure => file, | ||
owner => $puppet_agent::params::user, | ||
group => $puppet_agent::params::group, | ||
mode => $mode, | ||
source => $source, | ||
require => File[$puppet_agent::params::local_packages_dir], | ||
joshcooper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
$body = @{ | ||
"version" = "<%= $puppet_agent::prepare::package_version %>" | ||
"dev" = "<%= $puppet_agent::prepare::package::dev %>" | ||
"os_name" = "<%= $facts['os']['family'] %>" | ||
"os_version" = "<%= $facts['os']['release']['major'] %>" | ||
"os_arch" = "<%= $facts['os']['architecture'] %>" | ||
"fips" = "<%= $facts['fips_enabled'] %>" | ||
} | ||
cthorn42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$username = "<%= $puppet_agent::prepare::package::download_username %>" | ||
$password = ConvertTo-SecureString "<%= $puppet_agent::prepare::package::download_password %>" -AsPlainText -Force | ||
$credential = New-Object System.Management.Automation.PSCredential($username, $password) | ||
try { | ||
Invoke-WebRequest -Uri "<%= $puppet_agent::prepare::package::source %>" ` | ||
-Body $body ` | ||
-Credential $credential ` | ||
-OutFile "<%= $puppet_agent::prepare::package::local_package_file_path %>" | ||
} catch [System.Net.WebException] { | ||
Write-Host "Network-related error: $($_.Exception.Message)" | ||
exit 1 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.