Puppet Class: profile::netbox::automation

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

Overview

Class: profile::netbox::automation

This profile creates and exposes git repositories created by automation.

Actions:

Initialize git repositories
Create an apache site to expose these repositories.

Requires:

Sample Usage:

include profile::netbox::automation

Parameters:

  • automation_service_hostname (Stdlib::Fqdn) (defaults to: lookup('profile::netbox::automation::git_hostname'))
  • frontends (Array[Stdlib::Fqdn]) (defaults to: lookup('netbox_frontend', {'default_value' => []}))
  • has_acme (Boolean) (defaults to: lookup('profile::netbox::acme', {'default_value' => true}))
  • nb_api (Stdlib::HTTPSUrl) (defaults to: lookup('profile::netbox::netbox_api'))
  • nb_ro_token (String) (defaults to: lookup('profile::netbox::tokens::read_only'))
  • dns_min_records (Integer) (defaults to: lookup('profile::netbox::automation::dns_min_records'))
  • active_server (Stdlib::Fqdn) (defaults to: lookup('profile::netbox::active_server'))


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
# File 'modules/profile/manifests/netbox/automation.pp', line 14

class profile::netbox::automation (
    Stdlib::Fqdn $automation_service_hostname = lookup('profile::netbox::automation::git_hostname'),
    Array[Stdlib::Fqdn] $frontends = lookup('netbox_frontend', {'default_value' => []}),
    Boolean $has_acme = lookup('profile::netbox::acme', {'default_value' => true}),
    Stdlib::HTTPSUrl $nb_api = lookup('profile::netbox::netbox_api'),
    String $nb_ro_token = lookup('profile::netbox::tokens::read_only'),
    Integer $dns_min_records = lookup('profile::netbox::automation::dns_min_records'),
    Stdlib::Fqdn $active_server = lookup('profile::netbox::active_server'),
) {
    $ssl_settings = ssl_ciphersuite('apache', 'strong', true)

    # Create automation git repositories
    $repo_path = '/srv/netbox-exports'
    $repos = ['dns']

    $repos.each |String $repo| {
        netbox::autogit { $repo:
            repo_path => $repo_path,
            frontends => $frontends,
        }
    }

    # Expose automation git repositories
    # (this reuses the Netbox certificates).
    httpd::site { $automation_service_hostname:
        content => template('profile/netbox/netbox-exports.wikimedia.org.erb'),
        require => Acme_chief::Cert['netbox'],
    }

    # Configuration for Netbox extras dns scripts
    $dns_repo_path = "${repo_path}/dns.git/"
    $icinga_state_file = '/var/run/netbox_generate_dns_snippets.state'
    file { '/etc/netbox/dns.cfg':
        owner   => 'netbox',
        group   => 'netbox',
        mode    => '0440',
        content => template('profile/netbox/dns.cfg.erb'),
    }

    file { $icinga_state_file:
        ensure => 'present',
        owner  => 'netbox',
        group  => 'netbox',
        mode   => '0644',
    }

    if $active_server == $::fqdn {
        $active_ensure = 'present'
    } else {
        $active_ensure = 'absent'
    }

    systemd::timer::job { 'check_netbox_uncommitted_dns_changes':
        ensure          => $active_ensure,
        description     => 'Run check for uncommitted DNS changes in Netbox and save state for NRPE',
        command         => '/srv/deployment/netbox-extras/dns/generate_dns_snippets.py commit --icinga-check "icinga-check"',
        interval        => {
            'start'    => 'OnUnitInactiveSec',
            'interval' => '5m',
        },
        logging_enabled => false,
        user            => 'netbox',
    }

    $check_command = '/usr/lib/nagios/plugins/check_json_file'
    $max_age = 4800  # 80 minutes
    file { $check_command:
        source => 'puppet:///modules/profile/netbox/check_json_file.py',
        mode   => '0755',
    }

    nrpe::monitor_service { 'check_uncommitted_dns_changes':
        ensure         => $active_ensure,
        check_interval => 5,
        retry_interval => 2,
        description    => 'Uncommitted DNS changes in Netbox',
        nrpe_command   => "${check_command} ${icinga_state_file} ${max_age}",
        notes_url      => 'https://wikitech.wikimedia.org/wiki/Monitoring/Netbox_DNS_uncommitted_changes',
    }

}