Puppet Class: cfweb

Inherits:
cfweb::global
Defined in:
manifests/init.pp

Overview

Parameters:

  • cluster (String[1])
  • is_secondary (Boolean) (defaults to: false)
  • standalone (Array[String[1]]) (defaults to: [])
  • backends (Array[String[1]]) (defaults to: [])
  • frontends (Array[String[1]]) (defaults to: [])
  • web_service (String[1]) (defaults to: 'cfnginx')
  • internal_face (String[1]) (defaults to: 'main')
  • cluster_hint (Array[String[1]]) (defaults to: [])
  • deployuser (String[1]) (defaults to: 'deployweb')
  • deployuser_auth_keys (Optional[Hash[String[1],Hash]]) (defaults to: undef)


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
# File 'manifests/init.pp', line 6

class cfweb (
    String[1] $cluster,
    Boolean $is_secondary = false,
    Array[String[1]] $standalone = [],
    Array[String[1]] $backends = [],
    Array[String[1]] $frontends = [],
    String[1] $web_service = 'cfnginx',
    String[1] $internal_face = 'main',
    Array[String[1]] $cluster_hint = [],
    String[1] $deployuser = 'deployweb',
    Optional[Hash[String[1],Hash]] $deployuser_auth_keys = undef,
) inherits cfweb::global {
    include cfnetwork
    include cfsystem
    include cflogsink

    validate_re($cluster, '^[a-z][a-z0-9_]*$')
    validate_re($web_service, '^[a-z][a-z0-9_]*$')

    $internal_addr = cfnetwork::bind_address($internal_face)
    $web_dir = '/www'
    $acme_challenge_group = 'acme_challenge'
    $acme_challenge_root = "${web_dir}/acme_challenge"

    if !$internal_addr {
        fail('$cfweb::internal_face must be set to interface with valid address')
    }

    cfsystem_info { 'cfweb':
        ensure => present,
        info   => {
            cluster      => $cluster,
            is_secondary => $is_secondary,
            web_service  => $web_service,
        }
    }

    cfweb::internal::clusterhost { $cluster:
        is_secondary => $is_secondary,
    }

    #---
    $cluster_instances = cfsystem::query([
        'from', 'resources', ['extract', [ 'certname', 'parameters' ],
            ['and',
                ['=', 'type', 'Cfweb::Internal::Clusterhost'],
                ['=', 'title', $cluster],
            ],
    ]]).reduce({}) |$memo, $val| {
        $host = $val['certname']
        merge($memo, {
            $host => $val['parameters']
        })
    }

    $cluster_hosts = cfsystem::stable_sort($cluster_instances.keys())
    $is_cluster = size($cluster_hosts) > 1

    $cluster_ipset = "cfweb_${cluster}"
    cfnetwork::ipset { $cluster_ipset:
        type => 'ip',
        addr => cfsystem::stable_sort(unique($cluster_hosts + $cluster_hint)),
    }

    #---
    $primary_host = $cluster_instances.reduce($::trusted['certname']) |$memo, $val| {
        if $val[1]['is_secondary'] {
            $memo
        } else {
            $val[0]
        }
    }

    if $primary_host != $::trusted['certname'] and
        $cfweb::is_secondary != true
    {
        fail([
            "Primary cfweb host for ${cluster} is already known: ${primary_host}.",
            'Please consider setting cfweb::is_secondary'
        ].join("\n"))
    }

    $primary_internal_host = "${internal_face}.${primary_host}"

    # Standalone - public facing
    # NOTE: they still can work in HA cluster
    #---
    $standalone.each |$site_name| {
        $site = $cfweb::global::sites[$site_name]

        if !($site =~ Hash) {
            cf_notify { "cfweb:standalone:${site_name}":
                message  =>"Site '${site_name}' is missing from cfweb::global::sites: ${site}",
                loglevel => 'err',
            }
        } else {
            create_resources(
                    pick($site['type'], 'cfweb::site'),
                    {
                        $site_name => {
                            is_backend => false,
                        }
                    },
                    $site - 'type'
            )
        }
    }


    # Backends - sites which expect proxy_protocol
    # NOTE: must face only load balancer
    #---
    $backends.each |$site_name| {
        $site = $cfweb::global::sites[$site_name]

        if !($site =~ Hash) {
            cf_notify { "cfweb:backends:${site_name}":
                message  =>"Site '${site_name}' is missing from cfweb::global::sites: ${site}",
                loglevel => 'err',
            }
        } else {
            create_resources(
                    pick($site['type'], 'cfweb::site'),
                    {
                        $site_name => {
                            is_backend => true,
                        }
                    },
                    $site - 'type'
            )
        }
    }


    # Frontends - load balancing with proxy_protocol
    #---
    $frontends.each |$site_name| {
        fail('TODO: frontends are not supported yet')
    }
}