From d04944fa9d832f22fb5d2d4afdcd5bf142ea9ea2 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Mon, 6 Apr 2015 10:05:18 +0000 Subject: [PATCH] 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 --- manifests/tunnel.pp | 15 ++++++++------- templates/autossh-command.erb | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) 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 %>