Defined Type: trafficserver::lua_script

Defined in:
modules/trafficserver/manifests/lua_script.pp

Overview

Define: trafficserver::lua_script

Add the Lua script defined in $source under /etc/trafficserver/lua/ and notify trafficserver.

For details about Lua scripting in Traffic Server, see: docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/ts_lua.en.html

Parameters

source

Lua script source file

unit_test

Busted unit test source file for this Lua script (optional)

Examples

trafficserver::lua_script { 'set-x-cache':
    source    => 'puppet:///modules/profile/trafficserver/set-x-cache.lua',
    unit_test => 'puppet:///modules/profile/trafficserver/set-x-cache_test.lua',
}

Parameters:

  • source (Wmflib::Sourceurl)
  • unit_test (Wmflib::Sourceurl) (defaults to: undef)
  • service_name (String) (defaults to: 'trafficserver')
  • config_prefix (Stdlib::Absolutepath) (defaults to: '/etc/trafficserver')


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'modules/trafficserver/manifests/lua_script.pp', line 24

define trafficserver::lua_script(
    Wmflib::Sourceurl $source,
    Wmflib::Sourceurl $unit_test=undef,
    String $service_name='trafficserver',
    Stdlib::Absolutepath $config_prefix='/etc/trafficserver',
) {
    if !defined(Trafficserver::Lua_infra["infra-${service_name}"]) {
        trafficserver::lua_infra{ "infra-${service_name}":
            service_name  => $service_name,
            config_prefix => $config_prefix,
        }
    }

    $lua_path = "${config_prefix}/lua"

    $defaults = {
        owner   => $trafficserver::user,
        require => File[$lua_path],
    }

    if $unit_test != undef {
        file { "${lua_path}/${title}_test.lua":
            *      => $defaults,
            source => $unit_test,
            before => File["${lua_path}/${title}.lua"],
        }
    }

    file { "${lua_path}/${title}.lua":
        *      => $defaults,
        source => $source,
    }

    # Upon Lua scripts modification, run busted and reload trafficserver iff
    # all tests are green
    File["${lua_path}/${title}.lua"] ~> Exec["unit_tests_${service_name}"] ~> Exec["trigger_lua_reload_${config_prefix}"] ~> Service[$service_name]
}