Refactor tunnel.pp params

Autossh parameters are only the monitoring port and the -f flag,
the rest are not specific to autossh but they belong to ssh.
Instead of complicating the signature of the class, let's just
put all ssh args as an array and expose monitoring and background
mode flags.

Change-Id: I886edb0a3ed61b81060db39a2b4ab1bb70658f44
This commit is contained in:
Ricardo Carrillo Cruz 2015-04-06 10:05:18 +00:00
parent da9eb4a323
commit d04944fa9d
2 changed files with 10 additions and 9 deletions

View File

@ -16,19 +16,20 @@
#
# A define to add an autossh tunnel
define autossh::tunnel (
$ensure = running,
$user,
$ssh_port = '22',
$ssh_host,
$ssh_user,
$ssh_key,
$local_forward_args = undef,
$remote_forward_args = undef,
$ssh_args,
$ensure = running,
$ssh_port = '22',
$monitoring_port = 0,
$run_in_background = True,
) {
service { '/usr/lib/autossh':
ensure => $ensure,
start => template('autossh/autossh-command.erb'),
stop => 'AUTOSSH_PID=`pidof autossh` && CHILD_PID=`pgrep -P $AUTOSSH_PID` && kill -9 $AUTOSSH_PID && kill -9 $CHILD_PID',
ensure => $ensure,
start => template('autossh/autossh-command.erb'),
stop => 'AUTOSSH_PID=`pidof autossh` && CHILD_PID=`pgrep -P $AUTOSSH_PID` && kill -9 $AUTOSSH_PID && kill -9 $CHILD_PID',
provider => base,
}
}

View File

@ -1,5 +1,5 @@
<% if @user == 'root' %>
/usr/lib/autossh/autossh -M 0 -N -f -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o "StrictHostKeyChecking no" <% if @local_forward_args %> -L <%= @local_forward_args %> <% end %> <% if @remote_forward_args %> -R <%= @remote_forward_args %> <% end %> -i <%= @ssh_key %> <%= @ssh_user %>@<%= @ssh_host %> -p <%= @ssh_port %>
/usr/lib/autossh/autossh -M <%= monitoring_port %> <% if @run_in_background %> -f <% end %> <%= @ssh_args %> -i <%= @ssh_key %> <%= @ssh_user %>@<%= @ssh_host %> -p <%= @ssh_port %>
<% else %>
su <%= @user %> -c '/usr/lib/autossh/autossh -M 0 -N -f -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o "StrictHostKeyChecking no" <% if @local_forward_args %> -L <%= @local_forward_args %> <% end %> <% if @remote_forward_args %> -R <%= @remote_forward_args %> <% end %> -i <%= @ssh_key %> <%= @ssh_user %>@<%= @ssh_host %> -p <%= @ssh_port %>'
su <%= @user %> -c '/usr/lib/autossh/autossh -M <%= monitoring_port %> <% if @run_in_background %> -f <% end %> <%= @ssh_args %> -i <%= @ssh_key %> <%= @ssh_user %>@<%= @ssh_host %> -p <%= @ssh_port %>'
<% end %>