Skip to content

Commit 083dc7b

Browse files
committed
Optionally manage logfile parent directory
If the logfile path is set to a subdir (e.g. /var/log/openvpn/$name/openvpn.log) someone needs to create that path. This is a good a place as any to add that feature. Signed-off-by: Florian Pritz <[email protected]>
1 parent 05620f8 commit 083dc7b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

manifests/server.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# @param duplicate_cn Allow multiple connections on one cn
1717
# @param local Interface for openvpn to bind to.
1818
# @param logfile Logfile for this openvpn server
19+
# @param manage_logfile_directory Manage the directory that the logfile is located in
20+
# @param logdirectory_user The owner user of the logfile directory
21+
# @param logdirectory_group The owner group of the logfile directory
1922
# @param port The port the openvpn server service is running on#
2023
# @param portshare The address and port to which non openvpn request shall be forwared, e.g. 127.0.0.1 8443
2124
# @param proto What IP protocol is being used.
@@ -135,6 +138,9 @@
135138
Boolean $duplicate_cn = false,
136139
String $local = $facts['ipaddress_eth0'],
137140
Variant[Boolean, String] $logfile = false,
141+
Boolean $manage_logfile_directory = false,
142+
String[1] $logdirectory_user = 'nobody',
143+
String[1] $logdirectory_group = 'nobody',
138144
String $port = '1194',
139145
Optional[String] $portshare = undef,
140146
Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6'] $proto = 'tcp',
@@ -241,6 +247,15 @@
241247
$lnotify = undef
242248
}
243249

250+
if $manage_logfile_directory {
251+
$logdir = dirname($logfile)
252+
file { $logdir:
253+
ensure => 'directory',
254+
owner => $logdirectory_user,
255+
group => $logdirectory_group,
256+
}
257+
}
258+
244259
# Selection block to enable or disable tls-server flag
245260
# Check if we want to run as a client or not
246261
if !$tls_client {

spec/defines/openvpn_server_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@
302302
'proto' => 'udp',
303303
'group' => 'someone',
304304
'user' => 'someone',
305-
'logfile' => '/var/log/openvpn/test_server.log',
305+
'logfile' => '/var/log/openvpn/server1/test_server.log',
306+
'manage_logfile_directory' => true,
307+
'logdirectory_user' => 'someone',
308+
'logdirectory_group' => 'someone',
306309
'status_log' => '/tmp/test_server_status.log',
307310
'dev' => 'tun1',
308311
'up' => '/tmp/up',
@@ -352,7 +355,8 @@
352355
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^compress lz4$}) }
353356
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^group\s+someone$}) }
354357
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^user\s+someone$}) }
355-
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^log\-append\s+/var/log/openvpn/test_server\.log$}) }
358+
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^log\-append\s+/var/log/openvpn/server1/test_server\.log$}) }
359+
it { is_expected.to contain_file('/var/log/openvpn/server1').with('ensure' => 'directory', 'owner' => 'someone', 'group' => 'someone') }
356360
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^status\s+/tmp/test_server_status\.log$}) }
357361
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^dev\s+tun1$}) }
358362
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^local\s+2\.3\.4\.5$}) }

0 commit comments

Comments
 (0)