Skip to content

Commit

Permalink
Prefix custom tables with custom- so they're loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarrientos committed Dec 9, 2020
1 parent f0bd879 commit 8b90e50
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
define nftables::config (
Optional[String] $content = undef,
Optional[Variant[String,Array[String,1]]] $source = undef,
String $prefix = 'custom-',
) {
$concat_name = "nftables-${name}"

Package['nftables'] -> concat {
$concat_name:
path => "/etc/nftables/puppet-preflight/${name}.nft",
path => "/etc/nftables/puppet-preflight/${prefix}${name}.nft",
ensure_newline => true,
owner => root,
group => root,
mode => '0640',
} ~> Exec['nft validate'] -> file {
"/etc/nftables/puppet/${name}.nft":
"/etc/nftables/puppet/${prefix}${name}.nft":
ensure => file,
source => "/etc/nftables/puppet-preflight/${name}.nft",
source => "/etc/nftables/puppet-preflight/${prefix}${name}.nft",
owner => root,
group => root,
mode => '0640',
Expand Down
1 change: 1 addition & 0 deletions manifests/inet_filter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

nftables::config {
'inet-filter':
prefix => '',
source => 'puppet:///modules/nftables/config/puppet-inet-filter.nft';
}

Expand Down
2 changes: 2 additions & 0 deletions manifests/ip_nat.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
class nftables::ip_nat inherits nftables {
nftables::config {
'ip-nat':
prefix => '',
source => 'puppet:///modules/nftables/config/puppet-ip-nat.nft';
'ip6-nat':
prefix => '',
source => 'puppet:///modules/nftables/config/puppet-ip6-nat.nft';
}

Expand Down
8 changes: 4 additions & 4 deletions spec/defines/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@
it { is_expected.to contain_concat('nftables-FOO-BAR') }
it {
is_expected.to contain_concat('nftables-FOO-BAR').with(
path: '/etc/nftables/puppet-preflight/FOO-BAR.nft',
path: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
ensure_newline: true,
mode: '0640',
)
}
it { is_expected.to contain_file('/etc/nftables/puppet/FOO-BAR.nft') }
it { is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft') }
it {
is_expected.to contain_file('/etc/nftables/puppet/FOO-BAR.nft').with(
is_expected.to contain_file('/etc/nftables/puppet/custom-FOO-BAR.nft').with(
ensure: 'file',
source: '/etc/nftables/puppet-preflight/FOO-BAR.nft',
source: '/etc/nftables/puppet-preflight/custom-FOO-BAR.nft',
mode: '0640',
)
}
Expand Down

0 comments on commit 8b90e50

Please sign in to comment.