Defined Type: squid::http_port

Defined in:
manifests/http_port.pp

Summary

Defines http_port entries for a squid server. By setting optional `ssl` parameter to `true` will create https_port entries instead.

Overview

Examples:

squid::http_port { '10000':
  options => 'accel vhost'
}
squid::http_port { '10001':
  ssl     => true,
  options => 'cert=/etc/squid/ssl_cert/server.cert key=/etc/squid/ssl_cert/server.key'
}
squid::http_port { '127.0.0.1:3128':
}

Results in a squid configuration of:
http_port 10000 accel vhost
https_port 10001 cert=/etc/squid/ssl_cert/server.cert key=/etc/squid/ssl_cert/server.key
http_port 127.0.0.1:3128

Parameters:

  • title

    The title/namevar may be in the form ‘port` or `host:port` to provide the below values. Otherwise, specify `port` explicitly, and `host` if desired.

  • port (Optional[Stdlib::Port]) (defaults to: undef)

    Defaults to the port of the namevar and is the port number to listen on.

  • host (Optional[Stdlib::Host]) (defaults to: undef)

    Defaults to the host part of the namevar and is the interface to listen on. If not specified, Squid listens on all interfaces.

  • options (Optional[String[1]]) (defaults to: undef)

    A string to specify any options for the default.

  • ssl (Boolean) (defaults to: false)

    When set to ‘true` creates https_port entries. Defaults to `false`.

  • order (String) (defaults to: '05')

    Order can be used to configure where in ‘squid.conf`this configuration section should occur.

See Also:



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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'manifests/http_port.pp', line 34

define squid::http_port (
  Optional[Stdlib::Port] $port    = undef,
  Optional[Stdlib::Host] $host    = undef,
  Boolean                $ssl     = false,
  Optional[String[1]]    $options = undef,
  String                 $order   = '05',
) {
  $_title = String($title)

  # Try to extract host/port from title if neither were specified as
  # parameters. Allowed formats: host:port and port.
  if $host == undef and $port == undef and $_title =~ /^(?:(.+):)?(\d+)$/ {
    $_host = $1
    if $_host !~ Optional[Stdlib::Host] {
      fail("invalid host \"${_host}\" determined from title")
    }

    $_port = Integer($2)
    if $_port !~ Stdlib::Port {
      fail("invalid port \"${_port}\" determined from title")
    }
  } else {
    $_host = $host
    $_port = $port
  }

  if $_port == undef {
    fail('port parameter was not specified and could not be determined from title')
  }

  if $_host != undef {
    $_host_port = "${_host}:${_port}"
  } else {
    $_host_port = String($_port)
  }

  $protocol = $ssl ? {
    true    => 'https',
    default => 'http',
  }

  concat::fragment { "squid_${protocol}_port_${_title}":
    target  => $squid::config,
    content => epp('squid/squid.conf.port.epp',
      {
        title     => $_title,
        protocol  => $protocol,
        host_port => $_host_port,
        options   => $options,
      }
    ),
    order   => "30-${order}",
  }

  if fact('os.selinux.enabled') {
    ensure_resource('selinux::port', "selinux port squid_port_t ${_port}",
      {
        ensure   => 'present',
        seltype  => 'squid_port_t',
        protocol => 'tcp',
        port     => $_port,
      }
    )
  }
}