Puppet Class: profile::netbox

Defined in:
modules/profile/manifests/netbox.pp

Overview

Class: profile::netbox

This profile installs all the Netbox related parts as WMF requires it

Actions:

Deploy Netbox
Install apache, gunicorn, configure reverse proxy to gunicorn, LDAP
authentication and database

Requires:

Sample Usage:

include profile::netbox

Parameters:

  • active_server (String) (defaults to: hiera('profile::netbox::active_server'))
  • slaves (Optional[Array[String]]) (defaults to: hiera('profile::netbox::slaves', undef))
  • slave_ipv4 (Stdlib::Ipv4) (defaults to: hiera('profile::netbox::slave_ipv4'))
  • slave_ipv6 (Stdlib::Ipv6) (defaults to: hiera('profile::netbox::slave_ipv6'))
  • nb_token (String) (defaults to: hiera('profile::netbox::tokens::read_write'))
  • ganeti_user (String) (defaults to: hiera('profile::ganeti::rapi::ro_user'))
  • ganeti_password (String) (defaults to: hiera('profile::ganeti::rapi::ro_password'))
  • nb_api (Stdlib::HTTPSUrl) (defaults to: hiera('profile::netbox::netbox_api'))
  • puppetdb_host (Stdlib::Host) (defaults to: hiera('puppetdb_host'))
  • puppetdb_microservice_port (Integer) (defaults to: hiera('profile::puppetdb::microservice::port'))
  • nb_ganeti_profiles (Hash[String, Hash[String, Scalar, 2, 2]]) (defaults to: hiera('profile::netbox::ganeti_sync_profiles'))


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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'modules/profile/manifests/netbox.pp', line 15

class profile::netbox (
    String $active_server = hiera('profile::netbox::active_server'),
    Optional[Array[String]] $slaves = hiera('profile::netbox::slaves', undef),
    Stdlib::Ipv4 $slave_ipv4 = hiera('profile::netbox::slave_ipv4'),
    Stdlib::Ipv6 $slave_ipv6 = hiera('profile::netbox::slave_ipv6'),
    String $nb_token = hiera('profile::netbox::tokens::read_write'),
    String $ganeti_user = hiera('profile::ganeti::rapi::ro_user'),
    String $ganeti_password = hiera('profile::ganeti::rapi::ro_password'),
    Stdlib::HTTPSUrl $nb_api = hiera('profile::netbox::netbox_api'),
    Stdlib::Host $puppetdb_host = hiera('puppetdb_host'),
    Integer $puppetdb_microservice_port = hiera('profile::puppetdb::microservice::port'),
    Hash[String, Hash[String, Scalar, 2, 2]] $nb_ganeti_profiles = hiera('profile::netbox::ganeti_sync_profiles')
) {

    include passwords::netbox
    $db_password = $passwords::netbox::db_password
    $secret_key = $passwords::netbox::secret_key
    $replication_pass = $passwords::netbox::replication_password
    $nb_ganeti_ca_cert = '/etc/ssl/certs/Puppet_Internal_CA.pem'
    $nb_puppetdb_ca_cert = $nb_ganeti_ca_cert
    $puppetdb_api = "https://${puppetdb_host}:${puppetdb_microservice_port}/"

    $reports_path = '/srv/deployment/netbox-reports'

    # Have backups because Netbox is used as a source of truth (T190184)
    include ::profile::backup::host
    backup::set { 'netbox': }
    class { '::postgresql::backup': }

    # Used for LDAP auth
    include passwords::ldap::wmf_cluster
    $proxypass = $passwords::ldap::wmf_cluster::proxypass

    # Define master postgres server
    $master = $active_server

    # Inspired by modules/puppetmaster/manifests/puppetdb/database.pp
    if $master == $::fqdn {
        # We do this for the require in postgres::db
        $require_class = 'postgresql::master'
        class { '::postgresql::master':
            root_dir => '/srv/postgres',
            use_ssl  => true,
        }
        $on_master = true
        postgresql::user { 'replication@netmon2001-ipv4':
            ensure   => present,
            user     => 'replication',
            database => 'replication',
            password => $replication_pass,
            cidr     => "${slave_ipv4}/32",
            master   => $on_master,
            attrs    => 'REPLICATION',
        }
        postgresql::user { 'replication@netmon2001-ipv6':
            ensure   => present,
            user     => 'replication',
            database => 'replication',
            password => $replication_pass,
            cidr     => "${slave_ipv6}/128",
            master   => $on_master,
            attrs    => 'REPLICATION',
        }
        # User for standby netbox server to query the master DB
        postgresql::user { 'netbox@netmon2001':
            ensure   => present,
            user     => 'netbox',
            database => 'netbox',
            password => $db_password,
            cidr     => "${slave_ipv4}/32",
            master   => $on_master,
        }
        # User for monitoring check running on slave server
        # who needs replication user rights and uses IPv6 (T185504)
        postgresql::user { 'netbox@netmon2001-ipv6':
            ensure   => present,
            user     => 'replication',
            database => 'netbox',
            password => $replication_pass,
            cidr     => "${slave_ipv6}/128",
            master   => $on_master,
        }

        # Create the netbox user for localhost
        # This works on every server and is used for read-only db lookups
        postgresql::user { 'netbox@localhost':
            ensure   => present,
            user     => 'netbox',
            database => 'netbox',
            password => $db_password,
            master   => $on_master,
        }

        # Create the database
        postgresql::db { 'netbox':
            owner   => 'netbox',
            require => Class[$require_class],
        }
        postgresql::user { 'prometheus@localhost':
            user     => 'prometheus',
            database => 'postgres',
            type     => 'local',
            method   => 'peer',
        }

        if $slaves {
            $slaves_ferm = join($slaves, ' ')
            # Access to postgres master from postgres slaves
            ferm::service { 'netbox_postgres':
                proto  => 'tcp',
                port   => '5432',
                srange => "(@resolve((${slaves_ferm})) @resolve((${slaves_ferm}), AAAA))",
            }
        }

    } else {
        $require_class = 'postgresql::slave'
        class { '::postgresql::slave':
            master_server    => $master,
            root_dir         => '/srv/postgres',
            replication_pass => $replication_pass,
            use_ssl          => true,
        }
        $on_master = false

        class { '::postgresql::slave::monitoring':
            pg_master   => $master,
            pg_user     => 'replication',
            pg_password => $replication_pass,
            pg_database => 'netbox',
            description => 'netbox Postgres',
        }
    }

    git::clone { 'operations/software/netbox-reports':
        ensure    => 'latest',
        directory => $reports_path,
    }

    class { '::netbox':
        directory     => '/srv/deployment/netbox/deploy/src',
        db_password   => $db_password,
        secret_key    => $secret_key,
        ldap_password => $proxypass,
        reports_path  => $reports_path,
    }
    $ssl_settings = ssl_ciphersuite('apache', 'strong', true)

    httpd::site { 'netbox.wikimedia.org':
        content => template('profile/netbox/netbox.wikimedia.org.erb'),
    }

    acme_chief::cert { 'netbox':
        puppet_svc => 'apache2',
    }
    if $active_server == $::fqdn {
        $monitoring_ensure = 'present'
    } else {
        $monitoring_ensure = 'absent'
    }

    monitoring::service { 'netbox-ssl':
        ensure        => $monitoring_ensure,
        description   => 'netbox SSL',
        check_command => 'check_ssl_http_letsencrypt!netbox.wikimedia.org',
        notes_url     => 'https://wikitech.wikimedia.org/wiki/Netbox',
    }

    monitoring::service { 'netbox-https':
        ensure        => $monitoring_ensure,
        description   => 'netbox HTTPS',
        check_command => 'check_https_url!netbox.wikimedia.org!https://netbox.wikimedia.org',
        notes_url     => 'https://wikitech.wikimedia.org/wiki/Netbox',
    }


    file { '/etc/netbox-ganeti-sync.cfg':
        owner   => 'deploy-librenms',
        group   => 'www-data',
        mode    => '0400',
        content => template('profile/netbox/netbox-ganeti-sync.cfg.erb')
    }

    file { '/etc/netbox-reports.cfg':
        owner   => 'deploy-librenms',
        group   => 'www-data',
        mode    => '0440',
        content => template('profile/netbox/netbox-reports.cfg.erb')
    }
}