diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..9a47cc4 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,21 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# == Class: autossh +# +class autossh () { + package { 'autossh': + ensure => 'present', + } +} diff --git a/manifests/tunnel.pp b/manifests/tunnel.pp new file mode 100644 index 0000000..2e2fb26 --- /dev/null +++ b/manifests/tunnel.pp @@ -0,0 +1,33 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# == Define: autossh::tunnel +# +# A define to add an autossh tunnel +define autossh::tunnel ( + $ensure = running, + $ssh_port = '22', + $ssh_host, + $ssh_user, + $ssh_key, + $local_forward_args = undef, + $remote_forward_args = undef, +) { + 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', + provider => base, + } +} diff --git a/templates/autossh-command.erb b/templates/autossh-command.erb new file mode 100644 index 0000000..60ea5f2 --- /dev/null +++ b/templates/autossh-command.erb @@ -0,0 +1,4 @@ +/usr/lib/autossh/autossh -M 0 -N -f -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o "Stric +tHostKeyChecking no" <% if @local_forward_args %> -L <%= @local_forward_args %> <% end %> <% if @rem +ote_forward_args %> -R <%= @remote_forward_args %> <% end %> -i <%= @ssh_key %> <%= @ssh_user %>@<%= + @ssh_host %> -p <%= @ssh_port %>