|
12 | 12 | #
|
13 | 13 | # Sample Usage: netrc::foruser("netrc_myuser": user => 'myuser', machine_user_password_triples => [['myserver.localdomain','myuser','pw'],['mysecondserver.localdomain','myuser','pw2']])
|
14 | 14 | # you can also override the full path by using the `file_path` parameter.
|
15 |
| -# [Remember: No empty lines between comments and class definition] |
16 | 15 | class netrc {
|
17 |
| - |
18 | 16 | }
|
19 | 17 |
|
20 |
| -define netrc::foruser( |
21 |
| - Enum["present", "absent"] $ensure = "present", |
22 |
| - Stdlib::Absolutepath $home_base_directory = "/home", |
23 |
| - String $user, |
24 |
| - String $filename = ".netrc", |
25 |
| - Stdlib::Absolutepath $file_path = "$home_base_directory/$user/$filename", |
26 |
| - Hash[String, Hash] $machine_login_password) { |
27 |
| - |
28 |
| - file { $file_path: |
29 |
| - ensure => $ensure, |
30 |
| - content => epp('netrc/netrc.epp', { |
31 |
| - machine_login_password => $machine_login_password |
32 |
| - }), |
33 |
| - mode => '0600', |
34 |
| - owner => "$user" |
| 18 | +define netrc::usermachine ( |
| 19 | + String $user, |
| 20 | + String $machine, |
| 21 | + String $login, |
| 22 | + Sensitive[String] $password, |
| 23 | + Optional[String] $group = $user, |
| 24 | + Optional[String] $filename = '.netrc', |
| 25 | + Optional[Stdlib::Absolutepath] $file_path = undef, |
| 26 | +) { |
| 27 | + $user_file = $user ? { |
| 28 | + 'root' => "/root/${filename}", |
| 29 | + default => "/home/${user}/${filename}", |
| 30 | + } |
| 31 | + $real_file_path = $file_path ? { |
| 32 | + undef => $user_file, |
| 33 | + default => $file_path, |
| 34 | + } |
| 35 | + if !defined(Concat[$real_file_path]) { |
| 36 | + concat { $real_file_path: |
| 37 | + ensure => present, |
| 38 | + mode => '0600', |
| 39 | + owner => $user, |
| 40 | + group => $group, |
| 41 | + ensure_newline => true, |
| 42 | + } |
| 43 | + concat::fragment { "${real_file_path}-header": |
| 44 | + target => $real_file_path, |
| 45 | + content => '# File content managed by Puppet', |
| 46 | + } |
| 47 | + } |
| 48 | + concat::fragment { "${user}-${machine}-${login}": |
| 49 | + target => $real_file_path, |
| 50 | + content => Sensitive(epp('netrc/netrc.epp', |
| 51 | + { |
| 52 | + machine => $machine, |
| 53 | + login => $login, |
| 54 | + password => $password, |
| 55 | + } |
| 56 | + )), |
35 | 57 | }
|
36 | 58 | }
|
0 commit comments