|
5 | 5 | # @param source
|
6 | 6 | # The source file for the puppet-agent package. Can use any of the data types
|
7 | 7 | # and protocols that the File resource's source attribute can.
|
| 8 | +# @param destination_name |
| 9 | +# The destination file name for the puppet-agent package. If no destination |
| 10 | +# is given, then the basename component of the source will be used as the |
| 11 | +# destination name. |
8 | 12 | class puppet_agent::prepare::package (
|
9 | 13 | Variant[String, Array] $source,
|
| 14 | + Optional[String] $destination_name = undef |
10 | 15 | ) {
|
11 | 16 | assert_private()
|
12 | 17 |
|
13 | 18 | file { $puppet_agent::params::local_packages_dir:
|
14 | 19 | ensure => directory,
|
15 | 20 | }
|
16 | 21 |
|
17 |
| - # In order for the 'basename' function to work correctly we need to change |
18 |
| - # any \s to /s (even for windows UNC paths) so that it will correctly pull off |
19 |
| - # the filename. Since this operation is only grabbing the base filename and not |
20 |
| - # any part of the path this should be safe, since the source will simply remain |
21 |
| - # what it was before and we can still pull off the filename. |
22 |
| - $package_file_name = basename(regsubst($source, "\\\\", '/', 'G')) |
| 22 | + if $destination_name { |
| 23 | + $package_file_name = $destination_name |
| 24 | + } else { |
| 25 | + # In order for the 'basename' function to work correctly we need to change |
| 26 | + # any \s to /s (even for windows UNC paths) so that it will correctly pull off |
| 27 | + # the filename. Since this operation is only grabbing the base filename and not |
| 28 | + # any part of the path this should be safe, since the source will simply remain |
| 29 | + # what it was before and we can still pull off the filename. |
| 30 | + $package_file_name = basename(regsubst($source, "\\\\", '/', 'G')) |
| 31 | + } |
| 32 | + |
23 | 33 | if $facts['os']['family'] =~ /windows/ {
|
24 | 34 | $local_package_file_path = windows_native_path("${puppet_agent::params::local_packages_dir}/${package_file_name}")
|
25 | 35 | $mode = undef
|
|
28 | 38 | $mode = '0644'
|
29 | 39 | }
|
30 | 40 |
|
31 |
| - file { $local_package_file_path: |
32 |
| - ensure => file, |
33 |
| - owner => $puppet_agent::params::user, |
34 |
| - group => $puppet_agent::params::group, |
35 |
| - mode => $mode, |
36 |
| - source => $source, |
37 |
| - require => File[$puppet_agent::params::local_packages_dir], |
| 41 | + # REMIND: redhat/suse with absolute_source |
| 42 | + # REMIND: debian with absolute_source |
| 43 | + # REMIND: solaris 10 |
| 44 | + # REMIND: solaris 11 with manage_repo |
| 45 | + # REMIND: aix |
| 46 | + # REMIND: darwin |
| 47 | + # REMIND: suse 11 and PE |
| 48 | + if $puppet_agent::collection =~ /core/ and $facts['os']['family'] =~ /windows/ { |
| 49 | + $download_username = getvar('puppet_agent::username', 'forge-key') |
| 50 | + $download_password = unwrap(getvar('puppet_agent::password')) |
| 51 | + |
| 52 | + $_download_puppet = windows_native_path("${facts['env_temp_variable']}/download_puppet.ps1") |
| 53 | + file { $_download_puppet: |
| 54 | + ensure => file, |
| 55 | + content => Sensitive(epp('puppet_agent/download_puppet.ps1.epp')), |
| 56 | + } |
| 57 | + |
| 58 | + exec { 'Download Puppet Agent': |
| 59 | + command => "${facts['os']['windows']['system32']}\\WindowsPowerShell\\v1.0\\powershell.exe \ |
| 60 | + -ExecutionPolicy Bypass \ |
| 61 | + -NoProfile \ |
| 62 | + -NoLogo \ |
| 63 | + -NonInteractive \ |
| 64 | + ${_download_puppet}", |
| 65 | + creates => $local_package_file_path, |
| 66 | + provider => powershell, |
| 67 | + } |
| 68 | + } else { |
| 69 | + file { $local_package_file_path: |
| 70 | + ensure => file, |
| 71 | + owner => $puppet_agent::params::user, |
| 72 | + group => $puppet_agent::params::group, |
| 73 | + mode => $mode, |
| 74 | + source => $source, |
| 75 | + require => File[$puppet_agent::params::local_packages_dir], |
| 76 | + } |
38 | 77 | }
|
39 | 78 | }
|
0 commit comments