Skip to content

Instantly share code, notes, and snippets.

@panterch
Created November 10, 2010 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panterch/671193 to your computer and use it in GitHub Desktop.
Save panterch/671193 to your computer and use it in GitHub Desktop.
authorized keys recipe
class authorized_keys {
# install the given keys in the users authorized_keys file
# user name is given as title, keys are names of template files located in
# the modules templates directory
#
# key names are expanded to $keydir/<name>.pub. This ensures minimal writing
# and maintains compatibility with other tools like gitosis.
define install( keys = [ "seb" ], keydir = "/etc/puppet/files/ssh_keys" ) {
$home = $title ? { "root" => "/root", default => "/home/$title" }
file { "$home/.ssh":
ensure => directory,
owner => $title,
mode => 700,
require => $title ? { "root" => undef, default => User[$title] } ,
}
$keyfiles = regsubst($keys, '^.+$', "$keydir/\0.pub")
file { "$home/.ssh/authorized_keys":
ensure => present,
owner => $title,
mode => 600,
content => inline_template("<%=keyfiles.map{ |f| open(f).read }.join()%>"),
require => File["$home/.ssh"],
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment