If we do not have a fact, notify out early
[mirror/dsa-puppet.git] / modules / ssh / manifests / keygen.pp
1 # create an ssh key for user
2 define ssh::keygen(
3   String $user = $name,
4 ) {
5   if $facts["${user}_user_exists"] == undef {
6     notify{"We do not have facters for user ${user} existance and keys -- add it to modules/debian_org/lib/facter/roleaccounts.rb": }
7   } elsif $facts["${user}_user_exists"] {
8     if ! $facts["${user}_key"] {
9       exec { "create-${user}-ssh-key":
10         command => @("EOF"),
11           /bin/su - ${user} -c 'mkdir -p -m 02700 .ssh && ssh-keygen -C "`whoami`@`hostname` (`date +%Y-%m-%d`)" -P "" -f .ssh/id_rsa -q'
12           | EOF
13         onlyif  => "/usr/bin/getent passwd ${user} > /dev/null && ! [ -e ~${user}/.ssh/id_rsa ]"
14       }
15     }
16   } else {
17     notify{"User ${user} does not exist on this host.  Will not create ssh key": }
18   }
19 }