Forge Home

varnish

Module to manage the Varnish Web Accelerator

9,196 downloads

8,920 latest version

4.6 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Support the Puppet Community by contributing to this module

You are welcome to contribute to this module by suggesting new features, currency updates, or fixes. Every contribution is valuable to help ensure that the module remains compatible with the latest Puppet versions and continues to meet community needs. Complete the following steps:

  1. Review the module’s contribution guidelines and any licenses. Ensure that your planned contribution aligns with the author’s standards and any legal requirements.
  2. Fork the repository on GitHub, make changes on a branch of your fork, and submit a pull request. The pull request must clearly document your proposed change.

For questions about updating the module, contact the module’s author.

Version information

  • 1.0.2 (latest)
  • 1.0.1
released May 28th 2015
This version is compatible with:

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'chartbeat-varnish', '1.0.2'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add chartbeat-varnish
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install chartbeat-varnish --version 1.0.2

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

chartbeat/varnish — version 1.0.2 May 28th 2015

Varnish

Puppet module for varnish.

Build Status

Example usage

The base class just installs varnish and stops the service. This is because varnish services are created in the varnish::instance defined type.

If you just want to install the varnish package but don't want it running:

include varnish

If you want to modify which version of varnish you want to run, there are currently two supported methods.

Class Parameters

class { 'varnish' :
  package_ensure => '1.2.3',
}

Hiera

---
varnish::package_ensure: '1.2.3'

Include with default parameters:

varnish::instance { 'instance0' : }

Include with multiple different storage types:

varnish::instance { 'instance0' :
  storage_file => ['file,/mnt/varnish/instance0/varnish_storage.bin,70%',
                   'persistent,/data/varnish/varnish_storage.bin,20%']
}

The varnish::instance type is fully configurable. All of the varnish options are available as parameters. If, for instance, you want to increase the thread pool max size you could specify that as a param.

All of the parameters are set to the defaults as defined in varnishd(1)

varnish::instance { 'instance0' :
  thread_pool_max => '1500',
}

VMODS

The varnish::instance class supports installing vmods. Currently it expects them to be installed via APT. There are plans to support building it from source, but that would require a custom provider which is not yet built.

To ensure that a given varnish::instance has the throttle vmod installed that it needs:

varnish::instance { 'instance0' :
  vmods => ['libvmod-throttle'],
}

Repo

This varnish module currently uses the public repo.varnish-cache.org debian repository. If you want to use another repo, you can do it like the varnish package above, with class parameters or hiera.

Class Parameters

class { 'varnish' :
  apt_location => 'http://some.other.repo',
  apt_repos    => 'main restricted universe',
  ...
}

Hiera

---
varnish::apt_location: 'http://some.other/repo'
varnish::apt_repos: 'repo-name'
varnish::apt_key: 'XXXXXX'
varnish::key_source: 'http://some.other/key.txt'
varnish::apt_include_src: false

Configs

The varnish::instance type ships with a pretty simple config. You can pass in your own vcl config by just specifying the following:

varnish::instance { 'instance0' :
  vcl_conf => 'puppet:///path/to/config/file.vcl',
}

Or if your config is a template, you can do that as well:

varnish::instance { 'instance0' :
  vcl_conf => 'path/to/template/file.vcl.erb',
}

Note that if you pass in your own config, you'll have to handle the backend configuration, backend probes, vmod imports, acls yourself

Extra conf

There is an extra_conf parameter that you can use as a way to customize the default vcl conf further, but also retaining much of the scaffolding present in the default vcl conf. When multiple subroutines are defined in varnish, varnish will concatentate them together, for example:

vcl_recv {
    if (req.restarts == 0) {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =
                req.http.X-Forwarded-For + ", " + client.ip;
        } else {
            set req.http.X-Forwarded-For = client.ip;
        }
    }
}

vcl_recv {
    # Serve up stale data for this long
    set req.grace = 6s;
}

Will result in the following compiled version:

vcl_recv {
    if (req.restarts == 0) {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =
                req.http.X-Forwarded-For + ", " + client.ip;
        } else {
            set req.http.X-Forwarded-For = client.ip;
        }
    }
    # Serve up stale data for this long
    set req.grace = 6s;
}

As long as a return(SUBROUTINE) is not hit somewhere higher up, processing will continue on through the vcl. The default vcl conf that ships with this module has no return statements (except for the PURGE request) so you can safely append your custom vcl configurations by just passing them in as extra_conf.

varnish::instance { 'instance0' :
  extra_conf => 'puppet:///path/to/extra/conf.vcl'
}

Testing

This module uses rspec-puppet, rspec-puppet-system and rspec-system-serverspec. To test, install the required gems through Bundler.

$ git clone git://github.com/chartbeat/puppet-varnish.git
$ cd puppet-varnish
$ bundle install
$ bundle exec rake spec
$ bundle exec rake acceptance

To perform acceptance tests, you'll need Vagrant installed.

See LICENSE file.