diff --git a/manifests/tunnel.pp b/manifests/tunnel.pp index 87c6e08..2a9425a 100644 --- a/manifests/tunnel.pp +++ b/manifests/tunnel.pp @@ -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, } } diff --git a/templates/autossh-command.erb b/templates/autossh-command.erb index 73eda26..ad7aad1 100644 --- a/templates/autossh-command.erb +++ b/templates/autossh-command.erb @@ -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 %>