Skip to content

Commit

Permalink
Add support for managing AUTOSTART on debian, fixes #124
Browse files Browse the repository at this point in the history
  • Loading branch information
luxflux committed Mar 6, 2015
1 parent 30ea4e9 commit 8fe2e3e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
15 changes: 12 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
# This module installs the openvpn service, configures vpn endpoints, generates
# client certificates, and generates client config files
#
# === Parameters
#
# [*autostart_all*]
# Boolean. Wether the openvpn instances should be started automatically on boot.
# Default: true
#
#
# === Examples
#
# * Installation:
# class { 'openvpn': }
# class { 'openvpn':
# autostart_all => true,
# }
#
#
# === Authors
Expand All @@ -32,7 +39,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
class openvpn {
class openvpn(
$autostart_all = true,
) {

class { 'openvpn::params': } ->
class { 'openvpn::install': } ->
Expand Down
7 changes: 6 additions & 1 deletion manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@
# String. Name of a openssl::ca resource to use config with
# Default: undef
#
# [*autostart*]
# Boolean. Enable autostart for this server if openvpn::autostart_all is false.
# Default: undef
#
# === Examples
#
# openvpn::client {
Expand Down Expand Up @@ -401,6 +405,7 @@
$sndbuf = undef,
$rcvbuf = undef,
$shared_ca = undef,
$autostart = undef,
) {

include openvpn
Expand Down Expand Up @@ -495,7 +500,7 @@
}
}

if $::osfamily == 'Debian' {
if ($::osfamily == 'Debian' and $::openvpn::autostart_all) or $autostart {
concat::fragment { "openvpn.default.autostart.${name}":
content => "AUTOSTART=\"\$AUTOSTART ${name}\"\n",
target => '/etc/default/openvpn',
Expand Down
29 changes: 22 additions & 7 deletions spec/defines/openvpn_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,29 @@

let(:facts) { { :osfamily => 'Debian', :operatingsystem => 'Debian', :concat_basedir => '/var/lib/puppet/concat' } }

# Configure to start vpn session
it { should contain_concat__fragment('openvpn.default.autostart.test_server').with(
'content' => "AUTOSTART=\"$AUTOSTART test_server\"\n",
'target' => '/etc/default/openvpn'
)}

it { should contain_file('/etc/openvpn/test_server.conf').with_content(/^group\s+nogroup$/) }

context 'enabled autostart' do
let(:pre_condition) { 'class { "openvpn": autostart_all => true }' }

# Configure to start vpn session
it { should contain_concat__fragment('openvpn.default.autostart.test_server').with(
'content' => "AUTOSTART=\"$AUTOSTART test_server\"\n",
'target' => '/etc/default/openvpn'
)}
end

context 'disabled autostart_all' do
let(:pre_condition) { 'class { "openvpn": autostart_all => false }' }

# Configure to start vpn session
it { should_not contain_concat__fragment('openvpn.default.autostart.test_server') }

context 'but machine has autostart' do
before { params['autostart'] = true }
it { should contain_concat__fragment('openvpn.default.autostart.test_server') }
end
end
end

context 'ldap' do
Expand Down Expand Up @@ -427,5 +443,4 @@
:enable => true,
)}
end

end

0 comments on commit 8fe2e3e

Please sign in to comment.