Skip to content

Commit b089a40

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

File tree

5 files changed

+201
-46
lines changed

5 files changed

+201
-46
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: 110 additions & 4 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 (default: `openvpn`).
261+
262+
The desired state of the package (default: `present`).
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

manifests/init.pp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,62 +51,60 @@
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
62-
63-
Class['openvpn::install']
64-
-> Class['openvpn::config']
65-
-> Class['openvpn']
66+
# Install with params
67+
class { 'openvpn::install':
68+
package_name => $package_name,
69+
package_ensure => $package_ensure,
70+
}
6671

67-
if $facts['service_provider'] != 'systemd' {
68-
class { 'openvpn::service':
69-
subscribe => [Class['openvpn::config'], Class['openvpn::install']],
70-
}
72+
class { 'openvpn::config': }
7173

72-
if empty($servers) {
73-
Class['openvpn::service'] -> Class['openvpn']
74-
}
74+
# Service with params
75+
class { 'openvpn::service':
76+
service_name => $service_name,
77+
service_enable => $service_enable,
78+
service_ensure => $service_ensure,
7579
}
7680

81+
# Ordering
82+
Class['openvpn::install']
83+
-> Class['openvpn::config']
84+
~> Class['openvpn::service']
85+
86+
# Existing loops unchanged
7787
$clients.each |$name, $params| {
78-
openvpn::client {
79-
default:
80-
* => $client_defaults;
81-
$name:
82-
* => $params;
88+
openvpn::client { $name:
89+
* => merge($client_defaults, $params),
8390
}
8491
}
8592

8693
$client_specific_configs.each |$name, $params| {
87-
openvpn::client_specific_config {
88-
default:
89-
* => $client_specific_config_defaults;
90-
$name:
91-
* => $params;
94+
openvpn::client_specific_config { $name:
95+
* => merge($client_specific_config_defaults, $params),
9296
}
9397
}
9498

9599
$revokes.each |$name, $params| {
96-
openvpn::revoke {
97-
default:
98-
* => $revoke_defaults;
99-
$name:
100-
* => $params;
100+
openvpn::revoke { $name:
101+
* => merge($revoke_defaults, $params),
101102
}
102103
}
103104

104105
$servers.each |$name, $params| {
105-
openvpn::server {
106-
default:
107-
* => $server_defaults;
108-
$name:
109-
* => $params;
106+
openvpn::server { $name:
107+
* => merge($server_defaults, $params),
110108
}
111109
}
112110
}

manifests/install.pp

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

7-
stdlib::ensure_packages(['openvpn'])
17+
stdlib::ensure_packages([$package_name], { 'ensure' => $package_ensure })
18+
819
if $openvpn::additional_packages {
920
stdlib::ensure_packages($openvpn::additional_packages)
1021
}
@@ -19,6 +30,6 @@
1930
file {
2031
["${openvpn::etc_directory}/openvpn", "${openvpn::etc_directory}/openvpn/keys", '/var/log/openvpn',]:
2132
ensure => directory,
22-
require => Package['openvpn'];
33+
require => Package[$package_name];
2334
}
2435
}

manifests/service.pp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#
2-
# @summary This class maintains the openvpn service.
2+
# @summary
3+
# This class maintains the OpenVPN service (community edition) or
4+
# the OpenVPN Access Server service if overridden.
35
#
4-
class openvpn::service {
6+
class openvpn::service (
7+
String[1] $service_name = 'openvpn',
8+
Boolean $service_enable = true,
9+
Enum['running','stopped'] $service_ensure = 'running',
10+
) {
511
if $openvpn::manage_service and !$openvpn::namespecific_rclink {
6-
service { 'openvpn':
7-
ensure => running,
8-
enable => true,
12+
service { $service_name:
13+
ensure => $service_ensure,
14+
enable => $service_enable,
915
hasrestart => true,
1016
hasstatus => true,
1117
}

0 commit comments

Comments
 (0)