Skip to content

Commit

Permalink
Re-add support for module load overrides
Browse files Browse the repository at this point in the history
This ability was lost in PR sous-chefs#234
  • Loading branch information
stlng2 authored and stlng committed Dec 17, 2024
1 parent 7f4b9cb commit 7e38c94
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ See `attributes/default.rb` for default values.
- `node['rsyslog']['server_per_host_template']` - Template to use in the `rsyslog::server` recipe when creating the `35-server-per-host.conf` file
- `node['rsyslog']['server_per_host_cookbook']` - Cookbook name to get the `node['rsyslog']['server_per_host_template']` template from
- `node['rsyslog']['imfile']['KEY']` - Set `imfile` module parameters of label `KEY` to value. e.g. `PollingInterval`. Consult rsyslog documentation for valid entries.
- `node['rsyslog']['modules']` - Array of modules to load in the main rsyslog config filex
- `node['rsyslog']['<module>_directives']` - Hash of module directives and their values that apply to each `node['rsyslog']['modules']` when the module is loaded

## Recipes

Expand Down
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
default['rsyslog']['priv_user'] = nil
default['rsyslog']['priv_group'] = nil
default['rsyslog']['modules'] = %w(imuxsock imklog)
default['rsyslog']['imuxsock_directives'] = { 'SysSock.Use' => 'off' }
default['rsyslog']['file_create_mode'] = '0640'
default['rsyslog']['dir_create_mode'] = '0755'
default['rsyslog']['umask'] = '0022'
Expand Down Expand Up @@ -151,7 +152,7 @@
'local7.*' => "#{node['rsyslog']['default_log_dir']}/boot.log",
}
default['rsyslog']['modules'] = %w(imuxsock imjournal)
default['rsyslog']['additional_directives'] = { 'IMJournalStateFile' => 'imjournal.state' }
default['rsyslog']['imjournal_directives'] = { 'UsePid' => 'system', 'StateFile' => 'imjournal.state' }
else
# format { facility => destination }
default['rsyslog']['default_facility_logs'] = {
Expand Down
5 changes: 2 additions & 3 deletions spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@

it do
is_expected.to render_file('/etc/rsyslog.conf').with_content('Config generated by Chef - manual edits will be overwritten')
%w(imuxsock imklog).each do |mod|
is_expected.to render_file('/etc/rsyslog.conf').with_content(/^module\(load="#{mod}"/)
end
is_expected.to render_file('/etc/rsyslog.conf').with_content(/^module\(load="imuxsock".*SysSock.Use=/)
is_expected.to render_file('/etc/rsyslog.conf').with_content(/^module\(load="imklog"/)
end

it do
Expand Down
13 changes: 4 additions & 9 deletions templates/default/rsyslog.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ $PreserveFQDN <%= node['rsyslog']['preserve_fqdn'] %>

<% if node['rsyslog']['modules'] && !node['rsyslog']['modules'].empty? %>
<% [*node['rsyslog']['modules']].each do |mod| %>
<% case mod -%>
<% when 'imuxsock' -%>
module(load="imuxsock" SysSock.Use="off")
<% when 'imjournal' -%>
module(load="imjournal" UsePid="system" StateFile="imjournal.state")
<% else -%>
module(load="<%= mod %>")
<% end %>
<% end %>
module(load="<%= mod %>"<%- if node['rsyslog']["#{mod}_directives"]
node['rsyslog']["#{mod}_directives"].each do |k, v| -%> <%= k %>="<%= v %>"<% end %>)
<%- end -%>
<%- end -%>
<% end %>

<% if node['rsyslog']['server'] -%>
Expand Down

0 comments on commit 7e38c94

Please sign in to comment.