Defined Type: psick::openssh::keygen
- Defined in:
- manifests/openssh/keygen.pp
Overview
Define: psick::openssh::keygen Brutally imported and adapted from: github.com/maestrodev/puppet-ssh_keygen/blob/master/manifests/init.pp Full credits to the Maestro Devs
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 |
# File 'manifests/openssh/keygen.pp', line 6
define psick::openssh::keygen (
Optional[String] $user = undef,
Optional[String] $type = undef,
Optional[Integer] $bits = undef,
Optional[String] $home = undef,
Optional[String] $filename = undef,
Optional[String] $comment = undef,
Optional[String] $options = undef,
Boolean $create_ssh_dir = false,
) {
$user_real = $user ? {
undef => $name,
default => $user,
}
$type_real = $type ? {
undef => 'rsa',
default => $type,
}
$home_real = $home ? {
undef => $user_real ? {
'root' => "/${user_real}",
default => "/home/${user_real}",
},
default => $home,
}
$filename_real = $filename ? {
undef => "${home_real}/.ssh/id_${type_real}",
default => $filename,
}
$base_dir = dirname($filename_real)
$type_opt = " -t ${type_real}"
if $bits { $bits_opt = " -b ${bits}" } else { $bits_opt = '' }
$filename_opt = " -f '${filename_real}'"
$n_passphrase_opt = " -N ''"
if $comment { $comment_opt = " -C '${comment}'" } else { $comment_opt = '' }
$options_opt = $options ? {
undef => undef,
default => " ${options}",
}
exec { "ssh_keygen-${name}":
command => "ssh-keygen${type_opt}${bits_opt}${filename_opt}${n_passphrase_opt}${comment_opt}${options_opt}",
user => $user_real,
creates => $filename_real,
path => '/bin:/sbin:/usr/bin:/usr/sbin',
}
if $create_ssh_dir {
psick::tools::create_dir { "openssh_keygen_${base_dir}":
path => $base_dir,
owner => $user_real,
before => Exec["ssh_keygen-${name}"],
}
}
}
|