41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'manifests/init.pp', line 41
define ssh_keygen (
Optional[String] $user = undef,
Enum['rsa', 'dsa', 'ecdsa', 'ed25519', 'rsa1'] $type = 'rsa',
Optional[Integer] $bits = undef,
Optional[Stdlib::Absolutepath] $home = undef,
Optional[Stdlib::Absolutepath] $filename = undef,
Optional[String] $comment = undef,
Optional[Array[String]] $options = undef,
) {
Exec { path => '/bin:/usr/bin' }
$_user = $user ? {
undef => $name,
default => $user,
}
$_home = $home ? {
undef => $_user ? {
'root' => "/${_user}",
default => "/home/${_user}",
},
default => $home,
}
$_filename = $filename ? {
undef => "${_home}/.ssh/id_${type}",
default => $filename,
}
$type_opt = shell_join(['-t', $type])
$bits_opt = $bits ? {
undef => undef,
default => shell_join(['-b', $bits])
}
$filename_opt = shell_join(['-f', $_filename])
$passphrase_opt = shell_join(['-N', ''])
$comment_opt = $comment ? {
undef => undef,
default => shell_join(['-C', $comment])
}
$options_opt = $options ? {
undef => undef,
default => shell_join($options),
}
$command = delete_undef_values(
[
'ssh-keygen',
$type_opt,
$bits_opt,
$filename_opt,
$passphrase_opt,
$comment_opt,
$options_opt,
]
)
exec { "ssh_keygen-${name}":
command => join($command, ' '),
user => $_user,
creates => $_filename,
}
}
|