Merge remote-tracking branch 'origin/master' into staging
[mirror/dsa-puppet.git] / modules / varnish / manifests / config.pp
diff --git a/modules/varnish/manifests/config.pp b/modules/varnish/manifests/config.pp
new file mode 100644 (file)
index 0000000..0598e60
--- /dev/null
@@ -0,0 +1,52 @@
+define varnish::config (
+       $listen = [':6081'],
+       $source=undef,
+       $content=undef,
+       $ensure = 'present',
+       $backend = "-s malloc,256m",
+) {
+       if $name != "default" {
+               fail ( "This module cannot setup non-default varnish instances yet." )
+       }
+
+       case $ensure {
+               present: {
+                       include varnish::base
+                       include stretch::network_online
+
+                       if ! ($source or $content) {
+                               fail ( "No configuration found for ${name}" )
+                       }
+
+                       $listenarr = [] + $listen
+                       $listenstr = join(prefix($listenarr, "-a "), " ")
+                       systemd::override { 'varnish':
+                               content  => @("EOF"),
+                                       [Unit]
+                                       After=network-online.target
+                                       [Service]
+                                       ExecStart=
+                                       ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F ${listenstr} -T localhost:6082 -f /etc/varnish/${name}.vcl -S /etc/varnish/secret -s ${backend}
+                                       | EOF
+                       }
+
+                       $dest = "/etc/varnish/${name}.vcl"
+                       if $content {
+                               file { "${dest}":
+                                       ensure  => $ensure,
+                                       content => $content,
+                                       notify  => Service["varnish"],
+                               }
+                       } elsif $source {
+                               file { "${dest}":
+                                       ensure  => $ensure,
+                                       source  => $source,
+                                       notify  => Service["varnish"],
+                                       }
+                       }
+               }
+               default: {
+                       fail ( "Can only deal with ensure=>present for now" )
+               }
+       }
+}