diff --git a/Gemfile b/Gemfile index 31ac32ea..47a068a5 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,6 @@ group :unit_tests do gem 'puppet-lint', '1.0.1', :require => false gem 'puppet-syntax', :require => false gem 'metadata-json-lint', :require => false -# gem 'json', :require => false end group :development do @@ -19,4 +18,4 @@ if puppetversion = ENV['PUPPET_GEM_VERSION'] gem 'puppet', puppetversion, :require => false else gem 'puppet', :require => false -end \ No newline at end of file +end diff --git a/manifests/init.pp b/manifests/init.pp index 4333b9c3..f1bbe535 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ -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': } -> diff --git a/manifests/server.pp b/manifests/server.pp index e2b0aee1..1e2c89db 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -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 { @@ -401,6 +405,7 @@ $sndbuf = undef, $rcvbuf = undef, $shared_ca = undef, + $autostart = undef, ) { include openvpn @@ -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', diff --git a/spec/defines/openvpn_server_spec.rb b/spec/defines/openvpn_server_spec.rb index 218b8659..ee991dd5 100644 --- a/spec/defines/openvpn_server_spec.rb +++ b/spec/defines/openvpn_server_spec.rb @@ -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 @@ -427,5 +443,4 @@ :enable => true, )} end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dc7e9f4a..506a1e8f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,2 +1,2 @@ -require 'rubygems' +require 'bundler/setup' require 'puppetlabs_spec_helper/module_spec_helper'