e45edd82465f646f4b0fd8b8152d3fbb7ed5c59c
[mirror/dsa-puppet.git] / modules / varnish / manifests / config.pp
1 define varnish::config (
2         $listen = [':6081'],
3         $source=undef,
4         $content=undef,
5         $ensure = 'present',
6         $backend = "-s malloc,256m",
7 ) {
8         if $name != "default" {
9                 fail ( "This module cannot setup non-default varnish instances yet." )
10         }
11
12         case $ensure {
13                 present: {
14                         include varnish::base
15
16                         if ! ($source or $content) {
17                                 fail ( "No configuration found for ${name}" )
18                         }
19
20                         $listenarr = [] + $listen
21                         $listenstr = join(prefix($listenarr, "-a "), " ")
22                         systemd::override { 'varnish':
23                                 content  => @("EOF"),
24                                         [Service]
25                                         ExecStart=
26                                         ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F ${listenstr} -T localhost:6082 -f /etc/varnish/${name}.vcl -S /etc/varnish/secret -s ${backend}
27                                         | EOF
28                         }
29
30                         $dest = "/etc/varnish/${name}.vcl"
31                         if $content {
32                                 file { "${dest}":
33                                         ensure  => $ensure,
34                                         content => $content,
35                                         notify  => Service["varnish"],
36                                 }
37                         } elsif $source {
38                                 file { "${dest}":
39                                         ensure  => $ensure,
40                                         source  => $source,
41                                         notify  => Service["varnish"],
42                                         }
43                         }
44                 }
45                 default: {
46                         fail ( "Can only deal with ensure=>present for now" )
47                 }
48         }
49 }