File: init.pp

package info (click to toggle)
puppet-module-voxpupuli-ssh-keygen 2.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 324 kB
  • sloc: ruby: 164; makefile: 12; sh: 10
file content (96 lines) | stat: -rw-r--r-- 2,179 bytes parent folder | download | duplicates (3)
1
2
3
4
5
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
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
# ssh_keygen
#
# @summary Generate ssh keys for a user resource using ssh_keygen.
#
# @example Generate ssh keys for any user using ssh_keygen. The user must exist before using the module
#  ssh_keygen { 'john': }
#
# @example If not using the default `/home/john`
#  ssh_keygen { 'john':
#    home => '/var/home'
#  }
#
# @example The key comment can also be overriden with
#  ssh_keygen { 'john':
#    comment => 'john key'
#  }

# @example Generate a dsa key
#  ssh_keygen { 'john':
#    type => 'dsa'
#  }
#
# @example specify the bit length
#  ssh_keygen { 'john':
#    bits => 4096
#  }
#
# @example Generate new host key
#  ssh_keygen { 'root':
#    filename => '/etc/ssh/ssh_host_rsa_key'
#  }
#
# @param user Username to create key for
# @param type Type of key to create
# @param bits Number of bits in key
# @param home Home directory for user
# @param filename Key filename
# @param comment Key comment
# @param options Additional options to pass on to ssh-keygen
#
define ssh_keygen (
  Optional[String] $user     = undef,
  Enum['rsa', 'dsa'] $type   = 'rsa',
  Optional[Integer] $bits    = undef,
  Optional[String] $home     = undef,
  Optional[String] $filename = undef,
  Optional[String] $comment  = undef,
  Optional[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 = " -t ${type}"

  $bits_opt = $bits ? {
    undef   => undef,
    default => " -b ${bits}"
  }

  $filename_opt = " -f '${_filename}'"
  $passphrase_opt = " -N ''"

  $comment_opt = $comment ? {
    undef   => undef,
    default => " -C '${comment}'",
  }

  $options_opt = $options ? {
    undef   => undef,
    default => " ${options}",
  }

  exec { "ssh_keygen-${name}":
    command => "ssh-keygen${type_opt}${bits_opt}${filename_opt}${passphrase_opt}${comment_opt}${options_opt}",
    user    => $_user,
    creates => $_filename,
  }
}