Skip to content

Instantly share code, notes, and snippets.

@jeff1evesque
Created October 3, 2019 10:34
Show Gist options
  • Save jeff1evesque/4df247dabc8a22062669c8b8e324a3c9 to your computer and use it in GitHub Desktop.
Save jeff1evesque/4df247dabc8a22062669c8b8e324a3c9 to your computer and use it in GitHub Desktop.
proto
###
### create_key.pp, create ssh key(s).
###
class sshkey::create_key {
$directory_path = '/etc/puppetlabs/puppetserver/ssh'
$ssh_keys = $::sshkey::params::ssh_keys
$ssh_keys.each |Integer $index, String $value| {
$ssh_key = basename($value, '.git')
$certs = [
"${directory_path}/${ssh_key}",
"${directory_path}/${ssh_key}.pub"
]
ssh_keygen { 'puppet':
type => 'rsa',
bits => 4096,
filename => "/etc/puppetlabs/puppetserver/ssh/${ssh_key}",
before => File[ $certs ]
}
file { $certs:
ensure => present,
owner => 'puppet',
group => 'root',
mode => '600',
}
}
}
###
### create_directory.pp, create directory.
###
class sshkey::create_directory {
$directories = [
'/etc/puppetlabs',
'/etc/puppetlabs/puppetserver',
'/etc/puppetlabs/puppetserver/ssh'
]
## create log directories
file { $directories:
ensure => 'directory',
owner => 'puppet',
group => 'root',
mode => '750',
}
}
###
### create_key.pp, create ssh key(s).
###
class sshkey::create_key {
$directory_path = '/etc/puppetlabs/puppetserver/ssh'
$ssh_keys = $::sshkey::params::ssh_keys
$ssh_keys.each |Integer $index, String $value| {
$ssh_key = basename($value, '.git')
$certs = [
"${directory_path}/${ssh_key}",
"${directory_path}/${ssh_key}.pub"
]
ssh_keygen { 'puppet':
type => 'rsa',
bits => 4096,
filename => "/etc/puppetlabs/puppetserver/ssh/${ssh_key}",
before => File[ $certs ]
}
file { $certs:
ensure => present,
owner => 'puppet',
group => 'root',
mode => '600',
}
}
}
###
### init.pp: create sshkey
###
class sshkey (
$sshkeys = $::puppetserver::params::ssh_keys
) inherits ::sshkey::params {
class { 'sshkey::create_directory': } ->
class { 'sshkey::create_key': } ->
class { 'sshkey::add_key': }
}
###
### params.pp: default class parameters.
###
class sshkey::params {
$hiera = lookup( { 'name' => 'puppetserver', 'default_value' => false } )
if $hiera {
$ssh_keys = $hiera['ssh_keys']
}
else {
$ssh_keys = []
}
}
##
## This file contains the puppetserver configurations.
##
puppetserver:
ssh_keys:
- '[email protected]:account/repo.git'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment