summaryrefslogtreecommitdiffstats
path: root/manifests/authorized_key.pp
blob: c05a529966ec3eaef25e9d0a58912e9a34a7c8ab (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
# wrapper to have some defaults.
define sshd::authorized_key(
    $ensure  = 'present',
    $type    = 'ssh-rsa',
    $key     = 'absent',
    $user    = $name,
    $target  = undef,
    $options = false,
){

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

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

    if $options {
      Ssh_authorized_key[$name]{
        options => $options,
      }
    }
  }
}