Puppet Class: r_profile::web_service::apache

Defined in:
manifests/web_service/apache.pp

Overview

R_profile::Web_service::Apache

Install and configure Apache webserver

Parameters:

  • website_hash (Any) (defaults to: hiera('r_profile::web_service::apache::website_hash',undef))
  • open_firewall (Any) (defaults to: hiera('r_profile::web_service::apache::open_firewall', false))
  • lb (Any) (defaults to: hiera('r_profile::web_service::apache::lb',true))
  • disable_php (Any) (defaults to: hiera('r_profile::web_service::apache::disable_php', false))
  • disable_mysql (Any) (defaults to: hiera('r_profile::web_service::apache::disable_mysql', false))
  • nagios_monitored (Any) (defaults to: hiera('r_profile::web_service::apache::nagios_monitored', true))


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'manifests/web_service/apache.pp', line 4

class r_profile::web_service::apache(
    $website_hash       = hiera('r_profile::web_service::apache::website_hash',undef),
    $open_firewall      = hiera('r_profile::web_service::apache::open_firewall', false),
    $lb                 = hiera('r_profile::web_service::apache::lb',true),
    $disable_php        = hiera('r_profile::web_service::apache::disable_php', false),
    $disable_mysql      = hiera('r_profile::web_service::apache::disable_mysql', false),
    $nagios_monitored   = hiera('r_profile::web_service::apache::nagios_monitored', true),
) {

  # port is always 80, you would have to changed listeners, etc to support
  # different/multiple ports
  $port = 80

  class { 'apache':
    default_vhost => false,
  }

  if ! $disable_php {
    include ::apache::mod::php
  }

  if ! $disable_mysql {
    class { 'mysql::bindings':
      php_enable => true,
    }
  }

  include ::apache::mod::ssl

  # firewall
  if $open_firewall and !defined(Firewall["100 ${::fqdn} HTTP ${port}"]) {
    firewall { "100 ${::fqdn} HTTP ${port}":
      dport  => $port,
      proto  => 'tcp',
      action => 'accept',
    }
  }

  # load balancer
  # setup the FACT that will tell us what IP address to use (run n)
  if is_string($lb) {
    $lb_address = $lb
  } else {
    if $pe_server_version {

      # attempt to lookup which nodes are classified as Haproxies
      # and use first.  Only do this if being run in agent-master mode
      $lb_addresses = query_nodes('Class[R_profile::Monitor::Haproxy]')

      if is_array($lb_addresses) {
        $lb_address = $lb_addresses[0]
      } else {
        $lb_address = false
      }
    } else {
      $lb_address = false
    }
  }
  if $lb_address and is_string($lb) {
    $source_ip = $source_ipaddress[$lb_address]
  } else {
    $source_ip = undef
  }

  if $lb {
    # export the IP address (run n+1)
    @@haproxy::balancermember { $fqdn:
      listening_service => 'apache',
      server_names      => $fqdn,
      ipaddresses       => $source_ip,
      ports             => $port,
      options           => 'check',
    }
  }

  # nagios for main host
  if $nagios_monitored {
    nagios::nagios_service_http { $fqdn:
      port => $port,
    }
  }

  # setup the default vhost here.  we always want one of these.  The main
  # apache module sets one of these up but doesn't let us set the
  # allow_overrides option (.htaccess) that basically every REST framework
  # needs these days...
  # Note we have to use a different title to avoid a name clash with the
  # module
  $default_vhost_docroot = '/var/www/html'
  apache::vhost { 'default-site':
    ensure      => present,
    docroot     => $default_vhost_docroot,
    priority    => '15',
    ip          => $ip,
    port        => $port,
    directories => [
      {
        path           => $default_vhost_docroot,
        allow_override => ['All'],
      },
    ],
  }

  file { '/var/www/html':
    ensure => directory,
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }

  if $website_hash {
    $website_hash.each |String $site_name, Hash $website| {

      $_docroot = "/var/www/${website['docroot']}"

      apache::vhost { $site_name:
        docroot        => $_docroot,
        manage_docroot => $website['manage_docroot'],
        port           => $port,
        priority       => $website['priority'],
        directories    => [
          {
            path           => $_docroot,
            allow_override => ['All'],
          },
        ],
      }

      # Add to load balancer if enabled and we should use a different listener
      if $lb and $website['lb_listener'] {
        # export the IP address (run n+1)
        @@haproxy::balancermember { "${site_name}-${::fqdn}":
          listening_service => $website['lb_listener'],
          server_names      => $site_name,
          ipaddresses       => $source_ip,
          ports             => $port,
          options           => 'check',
        }
      }

      # nagios for VHOST
      if $nagios_monitored {
        nagios::nagios_service_http { $site_name:
          port => $port,
        }
      }
    }
  }
}