Defined Type: sshkeys::manual

Defined in:
manifests/manual.pp

Overview

Sshkeys::Manual

Manually import a set of ssh keys for a given user. File can be supplied inline as strings or via URIs suitable for the source attribute of the puppet file resource. It is an error to specify both content and source

Parameters:

  • user (Any) (defaults to: $title)

    User to install keys for

  • home (Any) (defaults to: "/home/${title}")

    Location of this user's home directory

  • group (Any) (defaults to: undef)

    Group that will own the installed keys

  • id_rsa (Any) (defaults to: undef)

    Content of the regular id_rsa (private key) file

  • id_rsa (defaults to: undef)

    Source of the regular id_rsa (private key) file. This can be any location understood by the puppet file resource

  • id_rsa_pub (Any) (defaults to: undef)

    Content of the regular id_rsa.pub (public key) file

  • id_rsa_pub_file (Any) (defaults to: undef)

    Source of the regular id_rsa_pub (public key) file. This can be any location understood by the puppet file resource

  • known_hosts (Any) (defaults to: undef)

    Content of the regular known_hosts file

  • known_hosts_file (Any) (defaults to: undef)

    Source of the regular known_hosts file. This can be any location understood by the puppet file resource

  • authorized_keys (Any) (defaults to: undef)

    Content of the regular authorized_keys file

  • authorized_keys_file (Any) (defaults to: undef)

    Source of the regular authorized_keys file. This can be any location understood by the puppet file resource

  • id_rsa_file (Any) (defaults to: undef)


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
# File 'manifests/manual.pp', line 22

define sshkeys::manual(
  $user                 = $title,
  $home                 = "/home/${title}",
  $group                = undef,
  $id_rsa               = undef,
  $id_rsa_file          = undef,
  $id_rsa_pub           = undef,
  $id_rsa_pub_file      = undef,
  $known_hosts          = undef,
  $known_hosts_file     = undef,
  $authorized_keys      = undef,
  $authorized_keys_file = undef,
) {

  if $group {
    $_group = $group
  } else {
    $_group = $user
  }

  $id_rsa_present = pick($id_rsa, $id_rsa_file, false) ? {
    false   => 'absent',
    default => 'file'
  }
  $id_rsa_pub_present = pick($id_rsa_pub, $id_rsa_pub_file, false) ? {
    false   => 'absent',
    default => 'file'
  }
  $known_hosts_present = pick($known_hosts, $known_hosts_file, false) ? {
    false   => 'absent',
    default => 'file'
  }
  $authorized_keys_present = pick($authorized_keys, $authorized_keys_file, false) ? {
    false   => 'absent',
    default => 'file'
  }

  File {
    mode  => "0600",
    owner => $user,
    group => $_group,
  }

  file { "${home}/.ssh":
    ensure => directory,
  }


  file { "${home}/.ssh/id_rsa":
    ensure  => $id_rsa_present,
    content => $id_rsa,
    source  => $id_rsa_file,
  }

  file { "${home}/.ssh/id_rsa.pub":
    ensure  => $id_rsa_pub_present,
    content => $id_rsa_pub,
    source  => $id_rsa_pub_file,
  }

  file { "${home}/.ssh/authorized_keys":
    ensure  => $authorized_keys_present,
    content => $authorized_keys,
    source  => $authorized_keys_file,
  }

  file { "${home}/.ssh/known_hosts":
    ensure  => $known_hosts_present,
    content => $known_hosts,
    source  => $known_hosts_file,
  }
}