Puppet Class: graylog::repository::apt

Defined in:
manifests/repository/apt.pp

Overview

Parameters:

  • url (Any)
  • release (Any)
  • version (Any)
  • proxy (Any)


1
2
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
# File 'manifests/repository/apt.pp', line 1

class graylog::repository::apt (
  $url,
  $release,
  $version,
  $proxy,
) {
  $apt_transport_package = 'apt-transport-https'
  $gpg_file = '/etc/apt/trusted.gpg.d/graylog-keyring.gpg'
  $package_sources = [
    'downloads.graylog.org',
    'graylog-downloads.herokuapp.com',
    'graylog2-package-repository.s3.amazonaws.com',
  ]

  anchor { 'graylog::repository::apt::begin': }

  if !defined(Package[$apt_transport_package]) {
    ensure_packages([$apt_transport_package])
  }

  file { $gpg_file:
    ensure => file,
    owner  => 'root',
    group  => 'root',
    mode   => '0444',
    source => 'puppet:///modules/graylog/graylog-keyring.gpg',
    notify => Exec['apt_update'],
  }

  apt::source { 'graylog':
    comment  => 'The official Graylog package repository',
    location => $url,
    release  => $release,
    repos    => $version,
    include  => {
      'deb' => true,
      'src' => false,
    },
    require  => [
      File[$gpg_file],
      Package[$apt_transport_package],
    ],
    notify   => Exec['apt_update'],
  }

  if $proxy {
    file { '/etc/apt/apt.conf.d/01_graylog_proxy':
      ensure => file,
    }
    # Each file_line resource will append http or https proxy info for its specified source into the 01_graylog_proxy file.
    # If a line already exists for that source, and doesn't match the provided proxy param, that line will be replaced.
    # If a line does not exist for that source, the provided info will be appended.
    $package_sources.each |String $source| {
      file_line { "Acquire::http::proxy::${source}":
        path    => '/etc/apt/apt.conf.d/01_graylog_proxy',
        match   => "Acquire::http::proxy::${source}",
        line    => "Acquire::http::proxy::${source} \"${proxy}\";",
        require => File['/etc/apt/apt.conf.d/01_graylog_proxy'],
        before  => Apt::Source['graylog'],
      }
      file_line { "Acquire::https::proxy::${source}":
        path    => '/etc/apt/apt.conf.d/01_graylog_proxy',
        match   => "Acquire::https::proxy::${source}",
        line    => "Acquire::https::proxy::${source} \"${proxy}\";",
        require => File['/etc/apt/apt.conf.d/01_graylog_proxy'],
        before  => Apt::Source['graylog'],
      }
    }
  }
  else {
    file { '/etc/apt/apt.conf.d/01_graylog_proxy':
      ensure => file,
    }
    # If proxy parameter has not been provided, remove any existing graylog package sources from the 01_graylog_proxy file (if
    # it exists)
    file_line { 'Remove graylog config from apt proxy file':
      ensure            => absent,
      path              => '/etc/apt/apt.conf.d/01_graylog_proxy',
      match             => 'graylog',
      match_for_absence => true,
      multiple          => true,
      before            => Apt::Source['graylog'],
    }
  }

  anchor { 'graylog::repository::apt::end': }

  Anchor['graylog::repository::apt::begin']
  -> Exec['apt_update']
  -> Anchor['graylog::repository::apt::end']
  -> Anchor['graylog::repository::end']
}