Skip to content

Commit

Permalink
Allow to include external keepalived config fragment not managed by t…
Browse files Browse the repository at this point in the history
…his Puppet module
  • Loading branch information
ymartin-ovh committed Feb 18, 2022
1 parent cf99985 commit c499252
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -332,6 +332,19 @@ class { '::keepalived':
}
```

### Opt out include unmanaged keepalived config files

If you need to include a Keepalived config fragment managed by another tool,
include_external_conf_files takes an array of config path.

**Caution: config file must be readable by Keepalived daemon**

```puppet
class { '::keepalived':
include_external_conf_files => ['/etc/keepalived/unmanaged-config.cfg']
}
```

### Unicast instead of Multicast

**Caution: unicast support has only been added to Keepalived since version 1.2.8**
Expand Down
8 changes: 8 additions & 0 deletions manifests/config.pp
Expand Up @@ -42,6 +42,14 @@
order => '001',
}

concat::fragment { 'keepalived.conf_include_external_configs':
target => "${keepalived::config_dir}/keepalived.conf",
content => epp('keepalived/include-external-configs.epp', {
'include_external_conf_files' => $keepalived::include_external_conf_files
}),
order => '998',
}

concat::fragment { 'keepalived.conf_footer':
target => "${keepalived::config_dir}/keepalived.conf",
content => "\n",
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Expand Up @@ -59,6 +59,8 @@
Stdlib::Filemode $config_dir_mode = '0755',
Stdlib::Filemode $config_file_mode = '0644',

Array[Stdlib::Absolutepath] $include_external_conf_files = [],

String[1] $config_group = 'root',
String[1] $config_owner = 'root',
String[1] $daemon_group = 'root',
Expand Down
30 changes: 30 additions & 0 deletions spec/acceptance/keepalived_spec.rb
Expand Up @@ -34,6 +34,7 @@ class { 'keepalived':

describe file('/etc/keepalived/keepalived.conf') do
it { is_expected.to be_file }
its(:content) { is_expected.not_to contain('include ') }
end
end

Expand Down Expand Up @@ -100,4 +101,33 @@ class { 'keepalived::global_defs':
its(:content) { is_expected.to contain('notification_email').from('global_defs').to('nospan@example.com') }
end
end

context 'with unmanaged external config' do
pp = <<-EOS
file { '/etc/keepalived/myconfig.conf':
owner => 'root',
group => 'root',
mode => '0644',
content => '',
notify => Class['keepalived::service']
}
class { 'keepalived':
include_external_conf_files => ['/etc/keepalived/myconfig.conf'],
sysconf_options => '-D --vrrp',
}
EOS

it 'works with no error' do
apply_manifest(pp, catch_failures: true)
end
it 'works idempotently' do
apply_manifest(pp, catch_changes: true)
end

describe file('/etc/keepalived/keepalived.conf') do
it { is_expected.to be_file }
its(:content) { is_expected.to contain('include /etc/keepalived/myconfig.conf') }
end
end
end
5 changes: 5 additions & 0 deletions templates/include-external-configs.epp
@@ -0,0 +1,5 @@
<%- | Array[Stdlib::Absolutepath] $include_external_conf_files
| -%>
<% $include_external_conf_files.each |$conf_file| { -%>
include <%= $conf_file %>
<% } -%>

0 comments on commit c499252

Please sign in to comment.