Puppet Class: mqtt

Defined in:
manifests/init.pp

Summary

Configure MQTT instance

Overview

Parameters:

  • datadir (String)

    handles storage of MQTT data

  • ip (String) (defaults to: '172.17.0.4')

    sets the IP of the mqtt container

  • metrics (Boolean) (defaults to: true)

    enables the mqtt-exporter sidecar container

  • metrics_ip (String) (defaults to: '172.17.0.5')

    sets the IP of the metrics container



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

class mqtt (
  String $datadir,
  String $ip = '172.17.0.4',
  Boolean $metrics = true,
  String $metrics_ip = '172.17.0.5',
) {
  firewall { '100 dnat for mqtt':
    chain  => 'DOCKER_EXPOSE',
    jump   => 'DNAT',
    proto  => 'tcp',
    dport  => 1883,
    todest => "${ip}:1883",
    table  => 'nat',
  }

  file { [
      $datadir,
      "${datadir}/mqtt_config",
      "${datadir}/mqtt_data",
    ]:
      ensure => directory,
  }

  docker::container { 'mqtt':
    image   => 'eclipse-mosquitto:2',
    args    => [
      "--ip ${ip}",
      "-v ${datadir}/mqtt_data:/mosquitto/data",
      "-v ${datadir}/mqtt_config:/mosquitto/config",
    ],
    cmd     => 'mosquitto -c /mosquitto-no-auth.conf',
    require => [File["${datadir}/mqtt_config"], File["${datadir}/mqtt_data"]],
  }

  if $metrics {
    firewall { '100 dnat for mqtt-exporter':
      chain  => 'DOCKER_EXPOSE',
      jump   => 'DNAT',
      proto  => 'tcp',
      dport  => 9000,
      todest => "${metrics_ip}:9000",
      table  => 'nat',
    }

    docker::container { 'mqtt-exporter':
      image => 'kpetrem/mqtt-exporter:latest',
      args  => [
        "--ip ${metrics_ip}",
        "-e MQTT_ADDRESS=${ip}",
      ],
    }
  }
}