dev/provisioning/modules/apache/manifests/balancer.pp
author ymh <ymh.work@gmail.com>
Wed, 28 Sep 2016 15:58:18 +0200
changeset 305 ff6cf3fc5f40
parent 28 b0b56e0f8c7f
permissions -rw-r--r--
api reorganisation and propagation if the changes + some code cleaning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
# == Define Resource Type: apache::balancer
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
# This type will create an apache balancer cluster file inside the conf.d
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
# directory. Each balancer cluster needs one or more balancer members (that can
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
# be declared with the apache::balancermember defined resource type). Using
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
# storeconfigs, you can export the apache::balancermember resources on all
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
# balancer members, and then collect them on a single apache load balancer
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
# server.
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
# === Requirement/Dependencies:
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
# Currently requires the puppetlabs/concat module on the Puppet Forge and uses
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
# storeconfigs on the Puppet Master to export/collect resources from all
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
# balancer members.
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
# === Parameters
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
# [*name*]
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
# The namevar of the defined resource type is the balancer clusters name.
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
# This name is also used in the name of the conf.d file
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
# [*proxy_set*]
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
# Hash, default empty. If given, each key-value pair will be used as a ProxySet
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
# line in the configuration.
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
# [*collect_exported*]
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
# Boolean, default 'true'. True means 'collect exported @@balancermember
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
# resources' (for the case when every balancermember node exports itself),
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
# false means 'rely on the existing declared balancermember resources' (for the
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
# case when you know the full set of balancermembers in advance and use
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
# apache::balancermember with array arguments, which allows you to deploy
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
# everything in 1 run)
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
# === Examples
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
# Exporting the resource for a balancer member:
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
# apache::balancer { 'puppet00': }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
#
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
define apache::balancer (
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
  $proxy_set = {},
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
  $collect_exported = true,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
) {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
  include ::apache::mod::proxy_balancer
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
  $target = "${::apache::params::confd_dir}/balancer_${name}.conf"
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
  concat { $target:
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    owner  => '0',
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    group  => '0',
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    mode   => '0644',
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    notify => Class['Apache::Service'],
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
  }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
  concat::fragment { "00-${name}-header":
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
    ensure  => present,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    target  => $target,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
    order   => '01',
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    content => "<Proxy balancer://${name}>\n",
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
  }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
  if $collect_exported {
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    Apache::Balancermember <<| balancer_cluster == $name |>>
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
  }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
  # else: the resources have been created and they introduced their
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
  # concat fragments. We don't have to do anything about them.
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
  concat::fragment { "01-${name}-proxyset":
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
    ensure  => present,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    target  => $target,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    order   => '19',
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    content => inline_template("<% @proxy_set.keys.sort.each do |key| %> Proxyset <%= key %>=<%= @proxy_set[key] %>\n<% end %>"),
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
  }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
  concat::fragment { "01-${name}-footer":
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    ensure  => present,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    target  => $target,
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    order   => '20',
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    content => "</Proxy>\n",
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
  }
b0b56e0f8c7f Add contributor edition
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
}