Puppet Class: vopsbot

Defined in:
modules/vopsbot/manifests/init.pp

Summary

install and run vopsbot

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • users (Hash[String, Vopsbot::User])

    list of authorised users

  • irc_server (String)

    the irc server to connect to

  • server_port (Stdlib::Port)

    the irc server port to connect to

  • nickname (String)

    irc nick to use

  • irc_channels (Array[String])

    list of channels to join

  • password (String)

    irc password to use

  • vo_api_id (String)

    VictorOps ID

  • vo_api_key (String)

    VictorOps API key

  • database_name (String) (defaults to: 'ircbot')

    name of the database to use

  • run_service (Boolean) (defaults to: false)

    indicate if we should run the service

  • daemon_user (String) (defaults to: 'vopsbot')

    the user used to run the vopsbot daemon



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

class vopsbot(
    Hash[String, Vopsbot::User] $users,
    String $irc_server,
    Stdlib::Port $server_port,
    String $nickname,
    Array[String] $irc_channels,
    String $password,
    String $vo_api_id,
    String $vo_api_key,
    String $database_name = 'ircbot',
    Boolean $run_service = false,
    String $daemon_user = 'vopsbot',
) {
    $data_path = '/srv/vopsbot'
    # Install the software
    package { 'vopsbot':
        ensure => present,
    }

    # TODO: add this to the debian package
    # https://gitlab.wikimedia.org/repos/sre/vopsbot/-/merge_requests/8
    systemd::sysuser { $daemon_user:
        ensure      => present,
        home_dir    => $data_path,
        description => 'vopsbot runner',
    }

    # configuration
    file { '/etc/vopsbot':
        ensure => directory,
        owner  => $daemon_user,
    }
    $ircbot_config = '/etc/vopsbot/ircbot-config.json'
    $user_config = '/etc/vopsbot/users.yaml'
    $db_path = "${data_path}/${database_name}.db"
    $config = {
        'server' => $irc_server,
        'port' => $server_port,
        'use_tls' => true,
        'use_sasl' => true,
        'nick' => $nickname,
        'password' => $password,
        'channels' => $irc_channels,
        'db_dsn'   => "sqlite3://file:${db_path}",
    }

    file { $ircbot_config:
        ensure  => file,
        owner   => $daemon_user,
        group   => $daemon_user,
        mode    => '0440',
        content => to_json($config),
        notify  => Systemd::Service['vopsbot'],
    }

    file { $user_config:
        ensure  => file,
        owner   => $daemon_user,
        group   => $daemon_user,
        mode    => '0440',
        content => to_yaml($users),
        notify  => Systemd::Service['vopsbot'],
    }

    file { $data_path:
        ensure => directory,
        owner  => $daemon_user,
        group  => $daemon_user,
        mode   => '0755',
    }
    # pre-generate the database
    # TODO: sync from active => passive instance.
    # TODO2: maybe use mysql
    $schema_file = "${data_path}/schema.sql"
    file { $schema_file:
        ensure => file,
        owner  => $daemon_user,
        group  => $daemon_user,
        mode   => '0440',
        source => 'puppet:///modules/vopsbot/schema.sql',
    }

    sqlite::db { 'vopsbot':
        ensure     => 'present',
        owner      => $daemon_user,
        group      => $daemon_user,
        db_path    => $db_path,
        sql_schema => $schema_file,
    }

    systemd::service { 'vopsbot':
        ensure               => $run_service.bool2str('present', 'absent'),
        override             => false,
        monitoring_enabled   => true,
        monitoring_notes_url => 'https://wikitech.wikimedia.org/wiki/Vopsbot',
        content              => template('vopsbot/systemd.unit.erb'),
        require              => Systemd::Sysuser[$daemon_user],
    }

    profile::auto_restarts::service { 'vopsbot':
        ensure => stdlib::ensure($run_service)
    }
}