AnarchoTechNYC / ansible-role-lighttpd

:computer::globe_with_meridians: Install a Lighttpd Web server on a computer with minimal resources.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Anarcho-Tech NYC: Lighttpd Build Status

An Ansible role for installing a Lighttpd server. Notably, this role has been tested with Raspbian on Raspberry Pi hardware. This role's purpose is to make it simple to install and run a Web server with minimal resources.

Role variables

To configure Lighttpd for a simple use case, several convenience variables are supplied:

Advanced Lighttpd configuration

This role features a relatively thorough Jinja template implementation of the Lighttpd configuration file format syntax. This means you can configure Lighttpd using the lighttpd_config list, whose items are dictionaries (two-dimensional associative arrays) that map nearly one-to-one to the Lighttpd module names and their keys. This implementation supports arbitrarily deeply nested conditionals, Lighttpd arrays, and simple variables.

The most complex part of the implementation is conditionals, which use the keyword conditional as the Lighttpd option list item name. The item itself is a list of dictionaries, each with the following required keys:

  • field
  • operator
  • value
  • options

All of these except options are described on the Lighttpd documentation for conditional configuration. The options item is itself a list of Lighttpd options that are to be applied if the conditional is matched. This list can include another conditional.

Note that Lighttpd is strict with regard to quote style. It exclusively uses double quotes, not single quotes. This means you should be careful to use proper quoting when defining the lighttpd_config list in your vars files.

Examples should help make this clear:

  1. Simple server bound to the alternate HTTP port, 8080.
    lighttpd_config:
      - server:
          port: 8080
      - server:
          document-root: "{{ lighttpd_server_home_dir }}/html"
    The above is equivalent to the Lighttpd configuration file:
    server.port = 8080
    server.document-root: "/var/www/html"
    
  2. Simple virtual host configuration with the default document root different from a domain-specific document root:
    lighttpd_config:
      - server:
          document-root: "{{ lighttpd_server_home_dir }}/html"
      - conditional:
        - field: '$HTTP["host"]'
          operator: '=~'
          value: '(^|\.)example\.com$' # Single quotes to protect `\.`, which is a Jinja2 escape sequence.
          options:
            - server:
                document-root: "{{ lighttpd_server_home_dir }}/example.com"
    The above is equivalent to the Lighttpd configuration file:
    server.document-root = "/var/www/html"
    $HTTP["host"] =~ "(^|\.)example\.com$" {
        server.document-root = "/var/www/html/example.com"
    }
    

See the defaults/main.yaml file for a more thorough example.

About

:computer::globe_with_meridians: Install a Lighttpd Web server on a computer with minimal resources.