Add all files needed to bring up VM and run agaric.com locally

This commit is contained in:
benjamin melançon 2018-08-20 10:45:20 -04:00
parent 52c8b60bac
commit 4d2bc0ee24
742 changed files with 24037 additions and 0 deletions

View file

@ -0,0 +1,2 @@
*.retry
tests/test.sh

View file

@ -0,0 +1,44 @@
---
services: docker
env:
- distro: centos7
- distro: centos6
- distro: ubuntu1604
- distro: ubuntu1404
- distro: debian9
- distro: debian8
# Also test installing older versions.
- distro: centos7
playbook: test-41.yml
varnish_version: "4.1"
- distro: ubuntu1604
varnish_version: "4.1"
playbook: test-41.yml
script:
# Configure test script so we can run extra tests after playbook is run.
- export container_id=$(date +%s)
- export cleanup=false
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh
# Run tests.
- ${PWD}/tests/test.sh
# Make sure Varnish is running.
- 'docker exec --tty ${container_id} env TERM=xterm varnishd -V'
# Test the version of Varnish installed (default to the main.yml default).
- |
varnish_version="${varnish_version:-5.1}"
docker exec --tty ${container_id} env TERM=xterm varnishd -V | grep "${varnish_version}"
# Test port 80.
- 'docker exec --tty ${container_id} env TERM=xterm curl -sI localhost:80 | grep -q "Via: .* varnish"'
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2017 Jeff Geerling
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,110 @@
# Ansible Role: Varnish
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-varnish.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-varnish)
Installs the [Varnish HTTP Cache](https://varnish-cache.org/) on RedHat/CentOS or Debian/Ubuntu Linux.
## Requirements
Requires the EPEL repository on RedHat/CentOS (you can install it using the `geerlingguy.repo-epel` role).
## Role Variables
Available variables are listed below, along with default values (see `defaults/main.yml`):
varnish_package_name: "varnish"
Varnish package name you want to install. See `apt-cache policy varnish` or `yum list varnish` for a listing of available candidates.
varnish_version: "5.1"
Varnish version that should be installed. See the [Varnish Cache packagecloud.io repositories](https://packagecloud.io/varnishcache) for a listing of available versions. Some examples include: `5.1`, `5.0`, `4.1`, `4.0`, `3.0`, and `2.1`.
varnish_config_path: /etc/varnish
The path in which Varnish configuration files will be stored.
varnish_use_default_vcl: true
Whether to use the included (simplistic) default Varnish VCL, using the backend host/port defined with the next two variables. Set this to `false` and copy your own `default.vcl` file into the `varnish_config_path` if you'd like to use a more complicated setup. If this variable is set to `true`, all other configuration will be taken from Varnish's own [default VCL](https://www.varnish-cache.org/trac/browser/bin/varnishd/default.vcl?rev=3.0).
varnish_default_vcl_template_path: default.vcl.j2
The default VCL file to be copied (if `varnish_use_default_vcl` is `true`). Defaults the the simple template inside `templates/default.vcl.j2`. This path should be relative to the directory from which you run your playbook.
varnish_listen_port: "80"
The port on which Varnish will listen (typically port 80).
varnish_default_backend_host: "127.0.0.1"
varnish_default_backend_port: "8080"
Some settings for the default "default.vcl" template that will be copied to the `varnish_config_path` folder. The default backend host/port could be Apache or Nginx (or some other HTTP server) running on the same host or some other host (in which case, you might use port 80 instead).
varnish_limit_nofile: 131072
The `nofiles` PAM limit Varnish will attempt to set for open files. The normal default is ~1024 which is much too low for Varnish usage.
varnish_secret: "14bac2e6-1e34-4770-8078-974373b76c90"
The secret/key to be used for connecting to Varnish's admin backend (for purge requests, etc.).
varnish_admin_listen_host: "127.0.0.1"
varnish_admin_listen_port: "6082"
The host and port through which Varnish will accept admin requests (like purge and status requests).
varnish_storage: "file,/var/lib/varnish/varnish_storage.bin,256M"
How Varnish stores cache entries (this is passed in as the argument for `-s`). If you want to use in-memory storage, change to something like `malloc,256M`. Please read Varnish's [Getting Started guide](http://book.varnish-software.com/4.0/chapters/Getting_Started.html) for more information.
varnish_pidfile: /run/varnishd.pid
Varnish PID file path. Set to an empty string if you don't want to use a PID file.
varnish_enabled_services:
- varnish
Services that will be started at boot and should be running after this role is complete. You might need to add additional services if required, e.g. `varnishncsa` and `varnishlog`. If set to an empty array, no services will be enabled at startup.
varnish_backends:
apache:
host: 10.0.2.2
port: 80
nodejs:
host: 10.0.2.3
port: 80
varnish_vhosts:
example.com:
backend: apache
nodejs.example.com:
backend: nodejs
You can configure multiple backends (and direct traffic from multiple virtual hosts to different backends) using the `varnish_backends` and `varnish_vhosts` variables. If you only use one backend (defined via `varnish_default_backend_host` and `varnish_default_backend_port`), then you do not need to define these variables. Do not add a `www` to the `vhosts` keys; it is added automatically by the `default.vcl.j2` VCL template.
## Dependencies
None.
## Example Playbook
- hosts: webservers
vars_files:
- vars/main.yml
roles:
- geerlingguy.varnish
*Inside `vars/main.yml`*:
varnish_secret: "[secret generated by uuidgen]"
varnish_default_backend_port: 81
... etc ...
## License
MIT / BSD
## Author Information
This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).

View file

@ -0,0 +1,39 @@
---
varnish_package_name: "varnish"
varnish_version: "5.1"
varnish_use_default_vcl: true
varnish_default_vcl_template_path: default.vcl.j2
varnish_default_backend_host: "127.0.0.1"
varnish_default_backend_port: "8080"
varnish_listen_port: "80"
varnish_secret: "14bac2e6-1e34-4770-8078-974373b76c90"
varnish_config_path: /etc/varnish
varnish_limit_nofile: 131072
varnish_admin_listen_host: "127.0.0.1"
varnish_admin_listen_port: "6082"
varnish_storage: "file,/var/lib/varnish/varnish_storage.bin,256M"
varnish_pidfile: /run/varnishd.pid
varnish_enabled_services:
- varnish
# Optionally define additional backends.
# varnish_backends:
# apache:
# host: 10.0.2.2
# port: 80
# nodejs:
# host: 10.0.2.3
# port: 80
# Optionally define vhosts pointed at different backends.
# varnish_vhosts:
# example.com:
# backend: apache
# nodejs.example.com:
# backend: nodejs

View file

@ -0,0 +1,6 @@
---
- name: reload systemd
command: systemctl daemon-reload
- name: restart varnish
service: name=varnish state=restarted

View file

@ -0,0 +1,24 @@
---
dependencies: []
galaxy_info:
author: geerlingguy
description: Varnish for Linux.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 2.2
platforms:
- name: EL
versions:
- 6
- 7
- name: Ubuntu
versions:
- precise
- trusty
- xenial
- name: Debian
versions:
- all
galaxy_tags:
- web

View file

@ -0,0 +1,95 @@
---
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
- name: Set the packagecloud repository name based on the version.
set_fact:
varnish_packagecloud_repo: "varnish{{ varnish_version|replace('.', '') }}"
- include: setup-RedHat.yml
when: ansible_os_family == 'RedHat'
- include: setup-Debian.yml
when: ansible_os_family == 'Debian'
- name: Ensure Varnish config path exists.
file:
path: "{{ varnish_config_path }}"
state: directory
- name: Copy Varnish configuration (sysvinit).
template:
src: varnish.j2
dest: "{{ varnish_sysvinit_config_path }}/varnish"
owner: root
group: root
mode: 0644
when: >
(ansible_os_family == 'RedHat' and ansible_distribution_major_version|int < 7) or
(ansible_os_family == 'Debian' and ansible_distribution_release != "xenial")
- name: Copy Debian Jessie/Xenial specific Varnish configs (systemd).
template:
src: varnish.service.j2
dest: "{{ varnish_systemd_config_path }}/varnish.service"
owner: root
group: root
mode: 0644
when: >
(ansible_distribution == 'Debian' and ansible_distribution_version|int >= 8) or
(ansible_distribution == 'Ubuntu' and ansible_distribution_version.split(".")[0]|int >= 16)
notify:
- reload systemd
- restart varnish
- name: Copy Varnish configuration (systemd).
template:
src: varnish.params.j2
dest: "{{ varnish_config_path }}/varnish.params"
owner: root
group: root
mode: 0644
when: >
(ansible_os_family == 'RedHat' and ansible_distribution_major_version|int >= 7) or
(ansible_os_family == 'Debian' and ansible_distribution_release == "xenial")
- name: Copy Varnish default VCL.
template:
src: "{{ varnish_default_vcl_template_path }}"
dest: "{{ varnish_config_path }}/default.vcl"
owner: root
group: root
mode: 0644
when: varnish_use_default_vcl
notify: restart varnish
- name: Copy varnish secret.
template:
src: secret.j2
dest: "{{ varnish_config_path }}/secret"
owner: root
group: root
mode: 0644
notify: restart varnish
- name: Ensure Varnish services are started and enabled on startup.
service:
name: "{{ item }}"
state: started
enabled: yes
with_items: "{{ varnish_enabled_services | default([]) }}"
when: >
varnish_enabled_services and
(ansible_os_family != 'Debian' and ansible_distribution_release != "xenial")
# See: https://github.com/ansible/ansible/issues/22303
- name: Ensure Varnish services are started enabled on startup (Xenial specific)
service:
name: "{{ item }}"
state: started
enabled: yes
use: "service"
with_items: "{{ varnish_enabled_services | default([]) }}"
when:
- varnish_enabled_services
- (ansible_os_family == 'Debian' and ansible_distribution_release == "xenial")

View file

@ -0,0 +1,26 @@
---
- name: Ensure APT HTTPS Transport is installed.
apt:
name: apt-transport-https
state: installed
- name: Add packagecloud.io Varnish apt key.
apt_key:
url: https://packagecloud.io/varnishcache/{{ varnish_packagecloud_repo }}/gpgkey
state: present
- name: Add packagecloud.io Varnish apt repository.
apt_repository:
repo: "deb https://packagecloud.io/varnishcache/{{ varnish_packagecloud_repo }}/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release }} main"
state: present
- name: Ensure Varnish is installed.
apt:
name: "{{ varnish_package_name }}"
state: present
- name: Ensure old role-managed Varnish systemd unit file is removed.
file:
path: /etc/systemd/system/varnish.service
state: absent
when: varnish_systemd_config_path != '/etc/systemd/system'

View file

@ -0,0 +1,30 @@
---
- name: Ensure Varnish dependencies are installed.
yum: name={{ item }} state=present
with_items:
- yum-utils
- pygpgme
- name: Add Varnish packagecloud.io yum repo.
yum_repository:
name: varnishcache_{{ varnish_packagecloud_repo }}
description: Varnish Cache packagecloud.io repository.
baseurl: https://packagecloud.io/varnishcache/{{ varnish_packagecloud_repo }}/el/{{ ansible_distribution_major_version|int }}/$basearch
repo_gpgcheck: no
gpgcheck: no
enabled: yes
gpgkey: https://packagecloud.io/varnishcache/{{ varnish_packagecloud_repo }}/gpgkey
sslverify: 1
sslcacert: /etc/pki/tls/certs/ca-bundle.crt
register: varnish_packagecloud_repo_addition
- name: Refresh yum metadata cache if repo changed.
command: >
yum clean metadata
warn=no
when: varnish_packagecloud_repo_addition.changed
- name: Ensure Varnish is installed.
yum:
name: "{{ varnish_package_name }}"
state: installed

View file

@ -0,0 +1,38 @@
{% if varnish_version | version_compare('4.0', '>=') %}
vcl 4.0;
{% endif %}
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
backend default {
.host = "{{ varnish_default_backend_host }}";
.port = "{{ varnish_default_backend_port }}";
}
{% if varnish_backends is defined %}
# Other backend servers.
{% for backend, value in varnish_backends.iteritems() %}
backend {{ backend }} {
.host = "{{ value.host }}";
.port = "{{ value.port }}";
}
{% endfor %}
{% endif %}
sub vcl_recv {
{% if varnish_vhosts is defined %}
# Varnish vhosts.
{% for vhost, value in varnish_vhosts.iteritems() if varnish_vhosts is defined %}
{% if loop.first %}
if (req.http.host == "{{ vhost }}" || req.http.host == "www.{{ vhost }}") {
{% else %}
elseif (req.http.host == "{{ vhost }}" || req.http.host == "www.{{ vhost }}") {
{% endif %}
set req.backend_hint = {{ value.backend }};
}
{% endfor %}
{% endif %}
}

View file

@ -0,0 +1 @@
{{ varnish_secret }}

View file

@ -0,0 +1,117 @@
# Configuration file for varnish
#
# /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this
# shell script fragment.
#
# Start varnish (only applies to Debian-based hosts)
START=yes
# Maximum number of open files (for ulimit -n)
NFILES={{ varnish_limit_nofile }}
# Locked shared memory (for ulimit -l)
# Default log size is 82MB + header
MEMLOCK=82000
# Maximum number of threads (for ulimit -u)
NPROCS="unlimited"
# Maximum size of corefile (for ulimit -c). Default in Fedora is 0
# DAEMON_COREFILE_LIMIT="unlimited"
# Set this to 1 to make init script reload try to switch vcl without restart.
# To make this work, you need to set the following variables
# explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,
# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,
# use Alternative 3, Advanced configuration, below
RELOAD_VCL=1
{% if varnish_pidfile %}
# Varnish PID file
PIDFILE="{{ varnish_pidfile }}"
{% endif %}
# This file contains 4 alternatives, please use only one.
## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080. Use a fixed-size cache file.
#
#DAEMON_OPTS="-a :6081 \
# -T localhost:6082 \
# -b localhost:8080 \
# -u varnish -g varnish \
# -s file,/var/lib/varnish/varnish_storage.bin,1G"
## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request. Use a
# fixed-size cache file.
#
#DAEMON_OPTS="-a :6081 \
# -T localhost:6082 \
# -f /etc/varnish/default.vcl \
# -u varnish -g varnish \
# -S /etc/varnish/secret \
# -s file,/var/lib/varnish/varnish_storage.bin,1G"
## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # Main configuration file. You probably want to change it :)
VARNISH_VCL_CONF={{ varnish_config_path }}/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT={{ varnish_listen_port }}
#
# # Telnet admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS={{ varnish_admin_listen_host }}
VARNISH_ADMIN_LISTEN_PORT={{ varnish_admin_listen_port }}
#
# # Shared secret file for admin interface
VARNISH_SECRET_FILE={{ varnish_config_path }}/secret
#
# # The minimum number of worker threads to start
VARNISH_MIN_THREADS=50
#
# # The Maximum number of worker threads to start
VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT=120
#
# # Backend storage specification
VARNISH_STORAGE="{{ varnish_storage }}"
#
# # Default TTL used when the backend does not specify one
VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
# # sure you update this section, too.
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
-t ${VARNISH_TTL} \
-p thread_pool_min=${VARNISH_MIN_THREADS} \
-p thread_pool_max=${VARNISH_MAX_THREADS} \
-p thread_pool_timeout=${VARNISH_THREAD_TIMEOUT} \
{% if varnish_version | version_compare('4.1', '<') %}
-u varnish -g varnish \
{% endif %}
-S ${VARNISH_SECRET_FILE} \
-s ${VARNISH_STORAGE}"
#
## Alternative 4, Do It Yourself. See varnishd(1) for more information.
#
# DAEMON_OPTS=""

View file

@ -0,0 +1,35 @@
# Varnish environment configuration description. This was derived from
# the old style sysconfig/defaults settings
# Set this to 1 to make systemd reload try to switch vcl without restart.
RELOAD_VCL=1
# Main configuration file. You probably want to change it.
VARNISH_VCL_CONF={{ varnish_config_path }}/default.vcl
# Default address and port to bind to. Blank address means all IPv4
# and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted
# quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=192.168.1.5
VARNISH_LISTEN_PORT={{ varnish_listen_port }}
# Admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS={{ varnish_admin_listen_host }}
VARNISH_ADMIN_LISTEN_PORT={{ varnish_admin_listen_port }}
# Shared secret file for admin interface
VARNISH_SECRET_FILE={{ varnish_config_path }}/secret
# Backend storage specification, see Storage Types in the varnishd(5)
# man page for details.
VARNISH_STORAGE="{{ varnish_storage }}"
# Default TTL used when the backend does not specify one
VARNISH_TTL=120
# User and group for the varnishd worker processes
VARNISH_USER=varnish
VARNISH_GROUP=varnish
# Other options, see the man page varnishd(1)
#DAEMON_OPTS="-p thread_pool_min=5 -p thread_pool_max=500 -p thread_pool_timeout=300"

View file

@ -0,0 +1,15 @@
[Unit]
Description=Varnish Cache, a high-performance HTTP accelerator
[Service]
Type=forking
{% if varnish_pidfile %}
PIDFile={{ varnish_pidfile }}
{% endif %}
LimitNOFILE={{ varnish_limit_nofile }}
LimitMEMLOCK=82000
ExecStart=/usr/sbin/varnishd -a :{{ varnish_listen_port }} -T {{ varnish_admin_listen_host }}:{{ varnish_admin_listen_port }}{% if varnish_pidfile %} -P {{ varnish_pidfile }}{% endif %} -f {{ varnish_config_path }}/default.vcl -S {{ varnish_config_path }}/secret -s {{ varnish_storage }}
ExecReload=/usr/share/varnish/reload-vcl
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,11 @@
# Ansible Role tests
To run the test playbook(s) in this directory:
1. Install and start Docker.
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
- `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
1. Make the test shim executable: `chmod +x tests/test.sh`.
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`
If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`

View file

@ -0,0 +1,9 @@
---
- name: Check what version of Varnish was installed.
command: varnishd -V
register: varnish_version
changed_when: no
- name: Display the installed Varnish version.
debug: var=varnish_version
changed_when: no

View file

@ -0,0 +1,20 @@
---
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
- name: Ensure build dependencies are installed (RedHat 7+).
yum: 'name="{{ item }}" state=present'
with_items:
- logrotate
- systemd-sysv
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version >= '7'
- name: Ensure build dependencies are installed (RedHat < 7).
yum: 'name="{{ item }}" state=present'
with_items:
- logrotate
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version < '7'
- name: Ensure curl is installed.
package: 'name=curl state=present'

View file

@ -0,0 +1,14 @@
---
- hosts: all
vars:
varnish_version: "4.1"
pre_tasks:
- include: setup.yml
roles:
- role_under_test
post_tasks:
- include: debug.yml

View file

@ -0,0 +1,10 @@
- hosts: all
pre_tasks:
- include: setup.yml
roles:
- role_under_test
post_tasks:
- include: debug.yml

View file

@ -0,0 +1,3 @@
---
varnish_sysvinit_config_path: /etc/default
varnish_systemd_config_path: /lib/systemd/system

View file

@ -0,0 +1,2 @@
---
varnish_sysvinit_config_path: /etc/sysconfig