root / manifests / config.pp @ 8d22a441
Historique | Voir | Annoter | Télécharger (1,66 ko)
1 |
# manage a config snippet |
---|---|
2 |
define nftables::config ( |
3 |
# lint:ignore:parameter_documentation |
4 |
Pattern[/^\w+-\w+$/] $tablespec = $title, |
5 |
Optional[String] $content = undef, |
6 |
Optional[Variant[String,Array[String,1]]] $source = undef, |
7 |
String $prefix = 'custom-', |
8 |
# lint:endignore |
9 |
) { |
10 |
if $content and $source { |
11 |
fail('Please pass only $content or $source, not both.') |
12 |
} |
13 |
|
14 |
$concat_name = "nftables-${name}" |
15 |
|
16 |
Package['nftables'] -> concat { |
17 |
$concat_name: |
18 |
path => "/etc/nftables/puppet-preflight/${prefix}${name}.nft", |
19 |
ensure_newline => true, |
20 |
owner => root, |
21 |
group => root, |
22 |
mode => '0640', |
23 |
} ~> Exec['nft validate'] -> file { |
24 |
"/etc/nftables/puppet/${prefix}${name}.nft": |
25 |
ensure => file, |
26 |
source => "/etc/nftables/puppet-preflight/${prefix}${name}.nft", |
27 |
owner => root, |
28 |
group => root, |
29 |
mode => '0640', |
30 |
} ~> Service['nftables'] |
31 |
|
32 |
$data = split($name, '-') |
33 |
|
34 |
concat::fragment { |
35 |
"${concat_name}-header": |
36 |
target => $concat_name, |
37 |
order => '00', |
38 |
content => "table ${data[0]} ${data[1]} {", |
39 |
} |
40 |
|
41 |
if $source { |
42 |
concat::fragment { |
43 |
"${concat_name}-body": |
44 |
target => $concat_name, |
45 |
order => 98, |
46 |
source => $source, |
47 |
} |
48 |
} else { |
49 |
if $content { |
50 |
$_content = $content |
51 |
} else { |
52 |
$_content = " include \"${name}-chain-*.nft\"" |
53 |
} |
54 |
concat::fragment { |
55 |
"${concat_name}-body": |
56 |
target => $concat_name, |
57 |
order => '98', |
58 |
content => $_content, |
59 |
} |
60 |
} |
61 |
|
62 |
concat::fragment { |
63 |
"${concat_name}-footer": |
64 |
target => $concat_name, |
65 |
order => '99', |
66 |
content => '}', |
67 |
} |
68 |
} |