Puppet Class: kafka

Defined in:
puppet/modules/kafka/manifests/init.pp

Overview

Class: Kafka

Parameters:

  • ssl_enabled (Any) (defaults to: false)


3
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
# File 'puppet/modules/kafka/manifests/init.pp', line 3

class kafka(
    $ssl_enabled = false,
) {
    require kafka::repository

    require_package('openjdk-11-jre')
    require_package('zookeeperd')
    require_package('confluent-kafka-2.11')
    require_package('kafkacat')

    $logdir = '/var/log/kafka'

    group { 'kafka':
        ensure  => 'present',
        system  => true,
        require => Package['confluent-kafka-2.11'],
    }
    # Kafka system user
    user { 'kafka':
        gid        => 'kafka',
        shell      => '/bin/false',
        home       => '/nonexistent',
        comment    => 'Apache Kafka',
        system     => true,
        managehome => false,
        require    => Group['kafka'],
    }

    file { '/usr/local/bin/kafka':
        source => 'puppet:///modules/kafka/kafka.sh',
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    # Install handy env vars in all shells so we don't have to specify
    # broker and zookeeper args every time using kafka CLI.
    file { '/etc/profile.d/kafka.sh':
        source => 'puppet:///modules/kafka/kafka.profile.sh',
    }

    if $ssl_enabled {
        file { '/etc/kafka/ssl':
            ensure  => 'directory',
            source  => 'puppet:///modules/kafka/ssl',
            recurse => true,
            owner   => 'root',
            group   => 'root',
            mode    => '0755',
        }
    }

    file { '/etc/kafka/server.properties':
        ensure  => 'present',
        content => template('kafka/server.properties.erb'),
        mode    => '0444',
        require => Package['confluent-kafka-2.11'],
    }

    file { '/etc/kafka/log4j.properties':
      ensure  => 'present',
      content => template('kafka/log4j.properties.erb'),
      mode    => '0444',
      require => Package['confluent-kafka-2.11'],
    }

    file { [$logdir, '/var/lib/kafka']:
        ensure  => 'directory',
        owner   => 'kafka',
        group   => 'kafka',
        mode    => '0755',
        require => Package['confluent-kafka-2.11'],
    }

    service { 'zookeeper':
        ensure  => 'running',
        enable  => true,
        require => Package['zookeeperd']
    }

    systemd::service { 'kafka':
        ensure         => 'present',
        service_params => {
            require   => [
                User['kafka'],
                Service['zookeeper'],
                Package['confluent-kafka-2.11'],
                Class['mediawiki::ready_service'],
            ],
            subscribe => [
                File['/etc/kafka/server.properties'],
                File['/etc/kafka/log4j.properties'],
            ]
        },
    }
}