Puppet push SSH key


The passwordless SSH worked well in my lab. Here is the how to:

1) Let the user generate the key pair, then copy the .pub file to the modules/sys_key/files folder and name it after the user’s name.

Selection_010

2) Copy /etc/skel/.bashrc and .bash_profile to modules/sys_key/files folder.

3) Create the the manifests files in module/sys_key/manifests. It can be download from here.

copy_key.pp

define sys_key::copy_key ($user) {

file { “/home/$user/”:
ensure => directory,
owner => $user,
#group => $user,
mode => 700,
replace => false,
}

file { “/home/$user/.ssh”:
ensure => directory,
owner => $user,
#group => $user,
mode => 700,
}

file { “/home/$user/.bash_profile”:
ensure => present,
owner => $user,
#group => $user,
source => “puppet:///sys_key/.bash_profile”,
}

file { “/home/$user/.bashrc”:
ensure => present,
owner => $user,
#group => $user,
source => “puppet:///sys_key/.bashrc”,
}

file { “/home/$user/.ssh/authorized_keys”:
ensure => present,
owner => $user,
#group => $user,
mode => 600,
source => “puppet:///sys_key/$user.pub”,
require => File[“/home/$user/.ssh”],
}

}

init.pp

class sys_key {
sys_key::copy_key { ‘jchen’: user => ‘jchen’ }
}

4) Apply the puppet tag, and test the paswordless ssh connection.

Selection_012

Selection_011

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s