Defined Type: aptly::mirror

Defined in:
manifests/mirror.pp

Summary

aptly::mirror Create a mirror using `aptly mirror create`. It will not update, snapshot, or publish the mirror for you, because it will take a long time and it doesn't make sense to schedule these actions frequenly in Puppet. NB: This will not recreate the mirror if the params change! You will need to manually `aptly mirror drop ` after also dropping all snapshot and publish references.

Overview

Parameters:

  • location (String)

    URL of the APT repo.

  • key (Variant[String[1], Hash[String[1],Variant[Array,Integer[1],String[1]]]]) (defaults to: {})

    This can either be a key id or a hash including key options. If using a hash, key => { ‘id’ => <id> } must be specified

  • filter (Optional[String[1]]) (defaults to: undef)

    Package query that is applied to packages in the mirror

  • release (String) (defaults to: $facts['os']['distro']['codename'])

    Distribution to mirror for.

  • repos (Array) (defaults to: [])

    Components to mirror. If an empty array then aptly will default to mirroring all components.

  • architectures (Array) (defaults to: [])

    Architectures to mirror. If attribute is ommited Aptly will mirror all available architectures.

  • with_sources (Boolean) (defaults to: false)

    Boolean to control whether Aptly should download source packages in addition to binary packages.

  • with_udebs (Boolean) (defaults to: false)

    Boolean to control whether Aptly should also download .udeb packages.

  • filter_with_deps (Boolean) (defaults to: false)

    Boolean to control whether when filtering to include dependencies of matching packages as well

  • environment (Array) (defaults to: [])

    Optional environment variables to pass to the exec. Example: [‘http_proxy=127.0.0.2:3128’]

  • keyring (String) (defaults to: '/etc/apt/trusted.gpg')

    path to the keyring used by aptly

  • force_components (Boolean) (defaults to: false)

    Boolean to control whether Aptly should force download of components.



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
# File 'manifests/mirror.pp', line 25

define aptly::mirror (
  String $location,
  Variant[String[1], Hash[String[1],Variant[Array,Integer[1],String[1]]]] $key = {},
  String $keyring            = '/etc/apt/trusted.gpg',
  Optional[String[1]] $filter = undef,
  String $release            = $facts['os']['distro']['codename'],
  Array $architectures       = [],
  Array $repos               = [],
  Boolean $with_sources      = false,
  Boolean $with_udebs        = false,
  Boolean $filter_with_deps  = false,
  Array $environment         = [],
  Boolean $force_components  = false,
) {
  include aptly

  $gpg_cmd = "/usr/bin/gpg --no-default-keyring --keyring ${keyring}"
  $aptly_cmd = "${aptly::aptly_cmd} mirror"

  if empty($architectures) {
    $architectures_arg = ''
  } else {
    $architectures_as_s = join($architectures, ',')
    $architectures_arg = "-architectures='${architectures_as_s}'"
  }

  if empty($repos) {
    $components_arg = ''
  } else {
    $components = join($repos, ' ')
    $components_arg = " ${components}"
  }

  $filter_arg = if $filter {
    " -filter=\"${filter}\""
  } else {
    ''
  }

  if ($filter_with_deps == true) {
    $filter_with_deps_arg = ' -filter-with-deps'
  } else {
    $filter_with_deps_arg = ''
  }

  # $aptly::key_server will be used as default key server
  # key in hash format
  if $key =~ Hash and $key[id] {
    if $key[id] =~ Array {
      $key_string = join($key[id], "' '")
    } else {
      $key_string = $key[id]
    }
    if $key[server] {
      $key_server = $key[server]
    } else {
      $key_server = $aptly::key_server
    }

    # key in string/array format
  } elsif $key =~ String {
    $key_server = $aptly::key_server
    $key_string = $key
  }

  # no GPG key
  if $key.empty {
    $exec_aptly_mirror_create_require = [
      Package['aptly'],
      File['/etc/aptly.conf'],
    ]
  } else {
    exec { "aptly_mirror_gpg-${title}":
      path    => $facts['path'],
      command => "${gpg_cmd} --keyserver '${key_server}' --recv-keys '${key_string}'",
      unless  => "echo '${key_string}' | xargs -n1 ${gpg_cmd} --list-keys",
      user    => $aptly::user,
    }

    $exec_aptly_mirror_create_require = [
      Package['aptly'],
      File['/etc/aptly.conf'],
      Exec["aptly_mirror_gpg-${title}"],
    ]
  }

  $force_components_arg = if $force_components {
    ' -force-components'
  } else {
    ''
  }

  exec { "aptly_mirror_create-${title}":
    command     => "${aptly_cmd} create ${architectures_arg} -with-sources=${with_sources} -with-udebs=${with_udebs}${filter_arg}${filter_with_deps_arg}${force_components_arg} ${title} ${location} ${release}${components_arg}",
    unless      => "${aptly_cmd} show ${title} >/dev/null",
    user        => $aptly::user,
    require     => $exec_aptly_mirror_create_require,
    environment => $environment,
  }
}