Defined Type: apt::repository

Defined in:
modules/apt/manifests/repository.pp

Overview

Parameters:

  • uri (Optional[Stdlib::HTTPUrl]) (defaults to: undef)
  • dist (Optional[String]) (defaults to: undef)
  • components (Optional[String]) (defaults to: undef)
  • bin (Boolean) (defaults to: true)
  • source (Boolean) (defaults to: true)
  • comment_old (Boolean) (defaults to: false)
  • keyfile (Optional[String]) (defaults to: undef)
  • ensure (Enum['present','absent']) (defaults to: present)
  • trust_repo (Boolean) (defaults to: false)


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

define apt::repository(
    Optional[Stdlib::HTTPUrl] $uri         = undef,
    Optional[String]          $dist        = undef,
    Optional[String]          $components  = undef,
    Boolean                   $bin         = true,
    Boolean                   $source      = true,
    Boolean                   $comment_old = false,
    Optional[String]          $keyfile     = undef,
    Enum['present','absent']  $ensure      = present,
    Boolean                   $trust_repo  = false,
) {
    if $ensure == 'present' and ! ($uri and $dist and $components) {
      fail('uri, dist and component are all required if ensure =>  present')
    }
    if $trust_repo {
        $trustedline = '[trusted=yes] '
    } else {
        $trustedline = ''
    }

    $binline = $bin ? {
        true    => "deb ${trustedline}${uri} ${dist} ${components}\n",
        default => '',
    }
    $srcline = $source ? {
        true    => "deb-src ${trustedline}${uri} ${dist} ${components}\n",
        default => '',
    }

    file { "/etc/apt/sources.list.d/${name}.list":
        ensure  => $ensure,
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        content => "${binline}${srcline}",
        notify  => Exec['apt-get update'],
    }

    if $comment_old {
        $escuri = regsubst(regsubst($uri, '/', '\/', 'G'), '\.', '\.', 'G')
        $binre = "deb(-src)?\s+${escuri}\s+${dist}\s"

        # comment out the old entries in /etc/apt/sources.list
        exec { "apt-${name}-sources":
            command => "/bin/sed -ri '/${binre}/s/^deb/#deb/' /etc/apt/sources.list",
            creates => "/etc/apt/sources.list.d/${name}.list",
            before  => File["/etc/apt/sources.list.d/${name}.list"],
        }
    }

    require_package('gnupg')

    if $keyfile {
        file { "/var/lib/apt/keys/${name}.gpg":
            ensure  => present,
            owner   => 'root',
            group   => 'root',
            mode    => '0400',
            source  => $keyfile,
            require => File['/var/lib/apt/keys'],
            before  => File["/etc/apt/sources.list.d/${name}.list"],
        }

        exec { "/usr/bin/apt-key add /var/lib/apt/keys/${name}.gpg":
            subscribe   => File["/var/lib/apt/keys/${name}.gpg"],
            refreshonly => true,
        }
    }
}