Skip to content

Commit 140e258

Browse files
committed
(install.pp) extend install features
1 parent cd9f30e commit 140e258

File tree

6 files changed

+208
-71
lines changed

6 files changed

+208
-71
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
Puppet module to manage OpenVPN servers and clients.
1212

13+
This module supports both:
14+
* **OpenVPN (community edition)** — the default package and service.
15+
* **OpenVPN Access Server (`openvpn-as`)** — installable by overriding parameters.
16+
1317
## Features
1418

1519
* Client-specific rules and access policies
@@ -40,6 +44,26 @@ The supported Puppet versions are listed in the [metadata.json](metadata.json)
4044

4145
Please see [REFERENCE.md](https://github.com/voxpupuli/puppet-openvpn/blob/master/REFERENCE.md) for more details.
4246

47+
## Additional Parameters
48+
49+
The following parameters were added to support OpenVPN Access Server
50+
and to make package/service management configurable:
51+
52+
- `package_name` (String, default: `openvpn`)
53+
Package name to install. Override with `openvpn-as` to install Access Server.
54+
55+
- `package_ensure` (String, default: `present`)
56+
Desired package state (e.g. `present`, `latest`, `absent`).
57+
58+
- `service_name` (String, default: `openvpn`)
59+
Name of the service resource to manage. Override with `openvpnas` for Access Server.
60+
61+
- `service_enable` (Boolean, default: `true`)
62+
Whether to enable the service at boot.
63+
64+
- `service_ensure` (Enum: `running`|`stopped`, default: `running`)
65+
Desired running state of the service.
66+
4367
## Example with hiera
4468

4569
```yaml
@@ -76,6 +100,16 @@ openvpn::revokes:
76100
77101
Don't forget the sysctl directive ```net.ipv4.ip_forward```!
78102

103+
## Example with OpenVPN Access Server (openvpn-as)
104+
105+
```yaml
106+
---
107+
classes:
108+
- openvpn
109+
110+
openvpn::package_name: 'openvpn-as'
111+
openvpn::service_name: 'openvpnas'
112+
```
79113
## Encryption Choices
80114

81115
This module provides certain default parameters for the openvpn encryption settings.

REFERENCE.md

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
* [`openvpn`](#openvpn): This module installs the openvpn service, configures vpn endpoints, generates client certificates, and generates client config files
1010
* [`openvpn::config`](#openvpn--config): This class sets up the openvpn enviornment as well as the default config file
11-
* [`openvpn::install`](#openvpn--install): This module installs the openvpn service, configures vpn endpoints, generates client certificates, and generates client config files
12-
* [`openvpn::service`](#openvpn--service): This class maintains the openvpn service.
11+
* [`openvpn::install`](#openvpn--install): This module installs and manages OpenVPN (community edition) or OpenVPN Access Server,
12+
* [`openvpn::service`](#openvpn--service): This class maintains the OpenVPN service (community edition) or
13+
the OpenVPN Access Server service if overridden.
1314

1415
### Defined types
1516

@@ -60,6 +61,11 @@ The following parameters are available in the `openvpn` class:
6061
* [`servers`](#-openvpn--servers)
6162
* [`server_directory`](#-openvpn--server_directory)
6263
* [`server_service_name`](#-openvpn--server_service_name)
64+
* [`package_name`](#-openvpn--package_name)
65+
* [`package_ensure`](#-openvpn--package_ensure)
66+
* [`service_name`](#-openvpn--service_name)
67+
* [`service_enable`](#-openvpn--service_enable)
68+
* [`service_ensure`](#-openvpn--service_ensure)
6369

6470
##### <a name="-openvpn--autostart_all"></a>`autostart_all`
6571

@@ -203,17 +209,117 @@ Data type: `String[1]`
203209

204210
Name of the openvpn server service. This is usually `openvpn`, but RHEL/CentOS 8 uses `openvpn-server`.
205211

212+
##### <a name="-openvpn--package_name"></a>`package_name`
213+
214+
Data type: `String[1]`
215+
216+
217+
218+
Default value: `'openvpn'`
219+
220+
##### <a name="-openvpn--package_ensure"></a>`package_ensure`
221+
222+
Data type: `String[1]`
223+
224+
225+
226+
Default value: `'present'`
227+
228+
##### <a name="-openvpn--service_name"></a>`service_name`
229+
230+
Data type: `String[1]`
231+
232+
233+
234+
Default value: `'openvpn'`
235+
236+
##### <a name="-openvpn--service_enable"></a>`service_enable`
237+
238+
Data type: `Boolean`
239+
240+
241+
242+
Default value: `true`
243+
244+
##### <a name="-openvpn--service_ensure"></a>`service_ensure`
245+
246+
Data type: `Enum['running','stopped']`
247+
248+
249+
250+
Default value: `'running'`
251+
206252
### <a name="openvpn--config"></a>`openvpn::config`
207253

208254
This class sets up the openvpn enviornment as well as the default config file
209255

210256
### <a name="openvpn--install"></a>`openvpn::install`
211257

212-
This module installs the openvpn service, configures vpn endpoints, generates client certificates, and generates client config files
258+
configures VPN endpoints, generates client certificates, and generates client config files.
259+
260+
The name of the package to install.
261+
262+
The desired state of the package.
263+
264+
#### Parameters
265+
266+
The following parameters are available in the `openvpn::install` class:
267+
268+
* [`package_name`](#-openvpn--install--package_name)
269+
* [`package_ensure`](#-openvpn--install--package_ensure)
270+
271+
##### <a name="-openvpn--install--package_name"></a>`package_name`
272+
273+
Data type: `String[1]`
274+
275+
276+
277+
Default value: `'openvpn'`
278+
279+
##### <a name="-openvpn--install--package_ensure"></a>`package_ensure`
280+
281+
Data type: `String[1]`
282+
283+
284+
285+
Default value: `'present'`
213286

214287
### <a name="openvpn--service"></a>`openvpn::service`
215288

216-
This class maintains the openvpn service.
289+
This class maintains the OpenVPN service (community edition) or
290+
the OpenVPN Access Server service if overridden.
291+
292+
#### Parameters
293+
294+
The following parameters are available in the `openvpn::service` class:
295+
296+
* [`service_name`](#-openvpn--service--service_name)
297+
* [`service_enable`](#-openvpn--service--service_enable)
298+
* [`service_ensure`](#-openvpn--service--service_ensure)
299+
300+
##### <a name="-openvpn--service--service_name"></a>`service_name`
301+
302+
Data type: `String[1]`
303+
304+
305+
306+
Default value: `'openvpn'`
307+
308+
##### <a name="-openvpn--service--service_enable"></a>`service_enable`
309+
310+
Data type: `Boolean`
311+
312+
313+
314+
Default value: `true`
315+
316+
##### <a name="-openvpn--service--service_ensure"></a>`service_ensure`
317+
318+
Data type: `Enum['running','stopped']`
319+
320+
321+
322+
Default value: `'running'`
217323

218324
## Defined types
219325

@@ -882,19 +988,13 @@ This define creates a revocation on a certificate for a specified server.
882988
#####
883989

884990
```puppet
885-
openvpn::client {
886-
'my_user':
887-
server => 'contractors'
888-
}
991+
openvpn::client { 'my_user': server => 'contractors' }
889992
```
890993

891994
#####
892995

893996
```puppet
894-
openvpn::revoke {
895-
'my_user':
896-
server => 'contractors'
897-
}
997+
openvpn::revoke { 'my_user': server => 'contractors' }
898998
```
899999

9001000
#### Parameters

manifests/init.pp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,62 +51,61 @@
5151
Hash $revokes = {},
5252
Hash $server_defaults = {},
5353
Hash $servers = {},
54+
55+
String[1] $package_name = 'openvpn',
56+
String[1] $package_ensure = 'present',
57+
String[1] $service_name = 'openvpn',
58+
Boolean $service_enable = true,
59+
Enum['running','stopped'] $service_ensure = 'running',
5460
) {
5561
$easyrsa_version = $facts['easyrsa'] ? {
5662
undef => $default_easyrsa_ver,
5763
default => $facts['easyrsa'],
5864
}
5965

60-
include openvpn::install
61-
include openvpn::config
66+
# Install with params
67+
class { 'openvpn::install':
68+
package_name => $package_name,
69+
package_ensure => $package_ensure,
70+
}
71+
72+
class { 'openvpn::config': }
73+
74+
# Service with params
75+
class { 'openvpn::service':
76+
service_name => $service_name,
77+
service_enable => $service_enable,
78+
service_ensure => $service_ensure,
79+
}
6280

81+
# Ordering
6382
Class['openvpn::install']
6483
-> Class['openvpn::config']
65-
-> Class['openvpn']
84+
~> Class['openvpn::service']
6685

67-
if $facts['service_provider'] != 'systemd' {
68-
class { 'openvpn::service':
69-
subscribe => [Class['openvpn::config'], Class['openvpn::install']],
70-
}
71-
72-
if empty($servers) {
73-
Class['openvpn::service'] -> Class['openvpn']
74-
}
75-
}
86+
# Existing loops unchanged
7687

7788
$clients.each |$name, $params| {
78-
openvpn::client {
79-
default:
80-
* => $client_defaults;
81-
$name:
82-
* => $params;
89+
openvpn::client { $name:
90+
* => $client_defaults + $params,
8391
}
8492
}
8593

8694
$client_specific_configs.each |$name, $params| {
87-
openvpn::client_specific_config {
88-
default:
89-
* => $client_specific_config_defaults;
90-
$name:
91-
* => $params;
95+
openvpn::client_specific_config { $name:
96+
* => $client_specific_config_defaults + $params,
9297
}
9398
}
9499

95100
$revokes.each |$name, $params| {
96-
openvpn::revoke {
97-
default:
98-
* => $revoke_defaults;
99-
$name:
100-
* => $params;
101+
openvpn::revoke { $name:
102+
* => $revoke_defaults + $params,
101103
}
102104
}
103105

104106
$servers.each |$name, $params| {
105-
openvpn::server {
106-
default:
107-
* => $server_defaults;
108-
$name:
109-
* => $params;
107+
openvpn::server { $name:
108+
* => $server_defaults + $params,
110109
}
111110
}
112111
}

manifests/install.pp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
# @summary This module installs and manages OpenVPN (community edition) or OpenVPN Access Server,
2+
# configures VPN endpoints, generates client certificates, and generates client config files.
13
#
2-
# @summary This module installs the openvpn service, configures vpn endpoints, generates client certificates, and generates client config files
4+
# @param package_name
5+
# The name of the package to install.
36
#
4-
class openvpn::install {
7+
# @param package_ensure
8+
# The desired state of the package.
9+
#
10+
class openvpn::install (
11+
String[1] $package_name = 'openvpn',
12+
String[1] $package_ensure = 'present',
13+
) {
514
include openvpn
615

7-
stdlib::ensure_packages(['openvpn'])
16+
stdlib::ensure_packages([$package_name], { 'ensure' => $package_ensure })
17+
818
if $openvpn::additional_packages {
919
stdlib::ensure_packages($openvpn::additional_packages)
1020
}
@@ -19,6 +29,6 @@
1929
file {
2030
["${openvpn::etc_directory}/openvpn", "${openvpn::etc_directory}/openvpn/keys", '/var/log/openvpn',]:
2131
ensure => directory,
22-
require => Package['openvpn'];
32+
require => Package[$package_name];
2333
}
2434
}

manifests/revoke.pp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
#
21
# @summary This define creates a revocation on a certificate for a specified server.
32
#
43
# @param server Name of the corresponding openvpn endpoint
54
# @example
6-
# openvpn::client {
7-
# 'my_user':
8-
# server => 'contractors'
9-
# }
5+
# openvpn::client { 'my_user': server => 'contractors' }
106
# @example
11-
# openvpn::revoke {
12-
# 'my_user':
13-
# server => 'contractors'
14-
# }
7+
# openvpn::revoke { 'my_user': server => 'contractors' }
158
#
169
define openvpn::revoke (
1710
String $server,
@@ -25,26 +18,21 @@
2518
$server_directory = $openvpn::server_directory
2619

2720
$revocation_command = $openvpn::easyrsa_version ? {
28-
'3.0' => "./easyrsa --batch revoke ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))'",
29-
default => fail("unexepected value for EasyRSA version, got '${openvpn::easyrsa_version}', expect 3.0."),
21+
'3.0' => "./easyrsa --batch revoke ${name}; echo \"exit $?\" | grep -qE '(error 23|exit (0|2))'",
22+
default => fail("unexpected value for EasyRSA version, got '${openvpn::easyrsa_version}', expect 3.0."),
3023
}
3124

3225
$renew_command = $openvpn::easyrsa_version ? {
3326
'3.0' => './easyrsa --batch gen-crl',
34-
default => fail("unexepected value for EasyRSA version, got '${openvpn::easyrsa_version}', expect 3.0."),
35-
}
36-
37-
file { "${server_directory}/${server}/easy-rsa/revoked/${name}":
38-
ensure => file,
39-
require => Exec["revoke certificate for ${name} in context of ${server}"],
27+
default => fail("unexpected value for EasyRSA version, got '${openvpn::easyrsa_version}', expect 3.0."),
4028
}
4129

4230
exec { "revoke certificate for ${name} in context of ${server}":
4331
command => $revocation_command,
4432
cwd => "${server_directory}/${server}/easy-rsa",
4533
provider => 'shell',
4634
notify => Exec["renew crl.pem on ${server} because of revocation of ${name}"],
47-
creates => "${server_directory}/${server}/easy-rsa/revoked/${name}",
35+
creates => "${server_directory}/${server}/easy-rsa/revoked/${name}", # restored for idempotency
4836
}
4937

5038
exec { "renew crl.pem on ${server} because of revocation of ${name}":

0 commit comments

Comments
 (0)