autossh.pp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. class sshd::autossh($host,
  2. $port = undef, # this should be a remote->local hash
  3. $remote_user = undef,
  4. $user = 'root',
  5. $pidfile = '/var/run/autossh.pid',
  6. ) {
  7. if $port {
  8. $port_ensure = $port
  9. }
  10. else {
  11. # random port between 10000 and 20000
  12. $port_ensure = fqdn_rand(10000) + 10000
  13. }
  14. if $remote_user {
  15. $remote_user_ensure = $remote_user
  16. }
  17. else {
  18. $remote_user_ensure = "host-$fqdn"
  19. }
  20. file {
  21. '/etc/init.d/autossh':
  22. mode => '0555',
  23. source => 'puppet:///modules/sshd/autossh.init.d';
  24. '/etc/default/autossh':
  25. mode => '0444',
  26. content => "USER=$user\nPIDFILE=$pidfile\nDAEMON_ARGS='-M0 -f -o ServerAliveInterval=15 -o ServerAliveCountMax=4 -q -N -R $port_ensure:localhost:22 $remote_user_ensure@$host'\n";
  27. }
  28. package { 'autossh':
  29. ensure => present,
  30. }
  31. service { 'autossh':
  32. ensure => running,
  33. enable => true,
  34. subscribe => [
  35. File['/etc/init.d/autossh'],
  36. File['/etc/default/autossh'],
  37. Package['autossh'],
  38. ],
  39. }
  40. }