module-sshd/manifests/autossh.pp

40 lines
1 KiB
ObjectPascal
Raw Normal View History

2015-06-18 21:58:51 +02:00
class sshd::autossh($host,
2015-06-18 22:07:18 +02:00
$port = undef, # this should be a remote->local hash
$remote_user = undef,
$user = 'root',
2015-06-18 21:58:51 +02:00
) {
if $port {
$port_ensure = $port
}
else {
# random port between 10000 and 20000
$port_ensure = fqdn_rand(10000) + 10000
}
if $remote_user {
$remote_user_ensure = $remote_user
}
else {
$remote_user_ensure = "host-$fqdn"
}
file {
'/etc/init.d/autossh':
mode => '0555',
source => 'puppet:///modules/sshd/autossh.init.d';
'/etc/default/autossh':
mode => '0444',
2015-06-18 22:07:18 +02:00
content => "USER=$user\nDAEMON_ARGS='-o ServerAliveInterval=15 -o ServerAliveCountMax=4 -q -N -R $port_ensure:localhost:22 $remote_user_ensure@$host'\n";
2015-06-18 21:58:51 +02:00
}
2015-06-18 21:59:16 +02:00
package { 'autossh':
ensure => present,
}
2015-06-18 21:58:51 +02:00
service { 'autossh':
ensure => running,
enable => true,
subscribe => [
2015-06-18 21:59:16 +02:00
File['/etc/init.d/autossh'],
File['/etc/default/autossh'],
Package['autossh'],
],
2015-06-18 21:58:51 +02:00
}
}