Skip to content

Commit

Permalink
Allow to use an array for extra_config_section
Browse files Browse the repository at this point in the history
The option "extra_config_section" can be defined as an array,
this adds the option to create multiple lines instead of one
big line with all the parameters.

This commit addresses issue #31
  • Loading branch information
ralfbosz committed Jun 30, 2017
1 parent e3a09f2 commit ba3fe12
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class{'::squid':
'http://example.com/anotherpath'],
},
},
http_access => { 'our_networks hosts' => { action => 'allow', },
http_ports => { '10000' => { options => 'accel vhost'} },
snmp_ports => { '1000' => { process_number => 3 },
cache_dirs => { '/data/' => { type => 'ufs', options => '15000 32 256 min-size=32769', process_number => 2 }},
http_access => { 'our_networks hosts' => { action => 'allow', }},
http_ports => { '10000' => { options => 'accel vhost', }},
snmp_ports => { '1000' => { process_number => 3, }},
cache_dirs => { '/data/' => { type => 'ufs', options => '15000 32 256 min-size=32769', process_number => 2, }},
}
```

Expand Down Expand Up @@ -424,6 +424,30 @@ mail_from [email protected]
mail_program mail
```

And using an array:

```puppet
squid::extra_config_section { 'refresh patterns':
order => '60',
config_entries => [{
'refresh_pattern' => ['^ftp: 1440 20% 10080',
'^gopher: 1440 0% 1440',
'-i (/cgi-bin/|\?) 0 0% 0',
'. 0 20% 4320'],
}],
}
```

Results in a squid configuration of

```
# refresh_patterns
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
```

#### Parameters for Type squid::extra\_config\_section
* `comment` defaults to the namevar and is used as a section comment in `squid.conf`.
* `config_entries` A hash of configuration entries to create in this section. The hash key is the name of the configuration directive. The value is either a string, or an array of strings to use as the configuration directive options.
Expand Down
7 changes: 3 additions & 4 deletions manifests/extra_config_section.pp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
define squid::extra_config_section (
String $comment = $title,
Hash $config_entries = {},
String $order = '60',
String $comment = $title,
Variant[Array,Hash] $config_entries = {},
String $order = '60',
) {

concat::fragment{"squid_extra_config_section_${comment}":
target => $::squid::config,
content => template('squid/squid.conf.extra_config_section.erb'),
order => "${order}-${comment}",
}

}
10 changes: 10 additions & 0 deletions templates/squid.conf.extra_config_section.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# <%= @comment %>
<% if @config_entries.is_a?(Array) -%>
<% @config_entries.each do |i| -%>
<% i.each do |k, v| -%>
<% v.each do |v2| -%>
<%= k %> <%= v2 %>
<% end -%>
<% end -%>
<% end -%>
<% else -%>
<% @config_entries.each do |k,v| -%>
<%= k %> <%= v.is_a?(Array) ? v.join(' ') : v %>
<% end -%>
<% end -%>

0 comments on commit ba3fe12

Please sign in to comment.