|
46 | 46 | String[1] $mode = '0755',
|
47 | 47 | Stdlib::Unixpath $state_file = golang::state_file($go_dir),
|
48 | 48 | ) {
|
| 49 | + $encoded_go_dir = $go_dir.regsubst('/', '_', 'G') |
| 50 | + $archive_path = "/tmp/puppet-golang${encoded_go_dir}.tar.gz" |
| 51 | + |
49 | 52 | if $ensure != any_version {
|
50 | 53 | # Used to ensure that the installation is updated when $source changes.
|
51 | 54 | $file_ensure = $ensure ? {
|
|
70 | 73 | }
|
71 | 74 | }
|
72 | 75 |
|
| 76 | + if $ensure == present or $ensure == any_version { |
| 77 | + # Remove Go installation if any of its files have the wrong user or group. |
| 78 | + # This will cause it to be replaced with a fresh installation. |
| 79 | + exec { "dp/golang check ownership of ${go_dir}": |
| 80 | + command => ['rm', '-rf', $go_dir], |
| 81 | + environment => [ |
| 82 | + "GO_DIR=${go_dir}", |
| 83 | + "OWNER=${owner}", |
| 84 | + "GROUP=${group}", |
| 85 | + ], |
| 86 | + path => ['/usr/local/bin', '/usr/bin', '/bin'], |
| 87 | + onlyif => 'find "$GO_DIR" "(" "(" -not -user "$OWNER" ")" -or "(" -not -group "$GROUP" ")" ")" -print -quit | grep .' |
| 88 | + before => File[$go_dir], |
| 89 | + notify => Archive[$archive_path], |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + # File[$state_file] changing should only trigger an update when ensure is |
| 94 | + # present, and not any_version. |
| 95 | + if $ensure == present { |
| 96 | + # If the $go_dir/bin directory exists, archive won't update it. Also, we |
| 97 | + # want to remove any files that are not present in the new version. |
| 98 | + exec { "dp/golang refresh go installation at ${go_dir}": |
| 99 | + command => ['rm', '-rf', $go_dir], |
| 100 | + path => ['/usr/local/bin', '/usr/bin', '/bin'], |
| 101 | + refreshonly => true, |
| 102 | + subscribe => File[$state_file], |
| 103 | + before => File[$go_dir], |
| 104 | + notify => Archive[$archive_path], |
| 105 | + } |
| 106 | + } |
| 107 | + |
73 | 108 | $directory_ensure = $ensure ? {
|
74 | 109 | 'present' => directory,
|
75 | 110 | 'any_version' => directory,
|
|
85 | 120 | }
|
86 | 121 |
|
87 | 122 | if $ensure == present or $ensure == any_version {
|
88 |
| - $encoded_go_dir = $go_dir.regsubst('/', '_', 'G') |
89 |
| - $archive_path = "/tmp/puppet-golang${encoded_go_dir}.tar.gz" |
90 |
| - |
91 |
| - # Only trigger an update when ensure is present, and not any_version. |
92 |
| - if $ensure == present { |
93 |
| - # If the $go_dir/bin directory exists, archive won't update it. Also, we |
94 |
| - # want to remove any files that are not present in the new version. |
95 |
| - exec { "dp/golang refresh go installation at ${go_dir}": |
96 |
| - command => ['rm', '-rf', $go_dir], |
97 |
| - path => ['/usr/local/bin', '/usr/bin', '/bin'], |
98 |
| - user => $facts['identity']['user'], |
99 |
| - refreshonly => true, |
100 |
| - subscribe => File[$state_file], |
101 |
| - before => File[$go_dir], |
102 |
| - notify => Archive[$archive_path], |
103 |
| - } |
104 |
| - } |
105 |
| - |
106 | 123 | include archive
|
107 | 124 |
|
108 | 125 | archive { $archive_path:
|
|
0 commit comments