aboutsummaryrefslogtreecommitdiff
path: root/manifests/ssh_authorized_key.pp
blob: 7201f8b9f123e3eaf64695f16d61720a13cf0ef9 (plain)
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
# wrapper to have some defaults.
define sshd::ssh_authorized_key(
    $ensure = 'present',
    $type = 'ssh-dss',
    $key = 'absent',
    $user = '',
    $target = undef,
    $options = 'absent'
){

  if ($ensure=='present') and ($key=='absent') {
    fail("You have to set \$key for Sshd::Ssh_authorized_key[${name}]!")
  }

  $real_user = $user ? {
    false   => $name,
    ''      => $name,
    default => $user,
  }

  case $target {
    undef,'': {
      case $real_user {
        'root': { $real_target = '/root/.ssh/authorized_keys' }
        default: { $real_target = "/home/${real_user}/.ssh/authorized_keys" }
      }
    }
    default: {
      $real_target = $target
    }
  }
  ssh_authorized_key{$name:
    ensure => $ensure,
    type   => $type,
    key    => $key,
    user   => $real_user,
    target => $real_target,
  }

  case $options {
    'absent': { info("not setting any option for ssh_authorized_key: ${name}") }
    default: {
      Ssh_authorized_key[$name]{
        options => $options,
      }
    }
  }
}