Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ apt::source { 'puppetlabs':
You can also generate a DEB822 format .sources file. This example covers most of the available options.

Use the `source_format` parameter to choose between 'list' and 'sources' (DEB822) formats.
Set the `apt` class parameter to use DEB822 as the default for all sources; an individual `apt::source` can still override it.

```puppet
class { 'apt':
source_format => 'sources',
}
```

```puppet
apt::source { 'debian':
source_format => 'sources'
Expand Down
15 changes: 12 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ The following parameters are available in the `apt` class:
* [`apt_conf_d`](#-apt--apt_conf_d)
* [`auth_conf_d`](#-apt--auth_conf_d)
* [`source_key_defaults`](#-apt--source_key_defaults)
* [`source_format`](#-apt--source_format)

##### <a name="-apt--provider"></a>`provider`

Expand Down Expand Up @@ -486,6 +487,14 @@ Default value:
}
```

##### <a name="-apt--source_format"></a>`source_format`

Data type: `Enum['list', 'sources']`

Default format for `apt::source` resources. Individual resources can override this. Sources using `key`, `pin`, or non-empty `include` values retain the `list` format when inheriting this default for backward compatibility.

Default value: `'list'`

### <a name="apt--backports"></a>`apt::backports`

Manages backports.
Expand Down Expand Up @@ -1201,11 +1210,11 @@ The following parameters are available in the `apt::source` defined type:

##### <a name="-apt--source--source_format"></a>`source_format`

Data type: `Enum['list', 'sources']`
Data type: `Optional[Enum['list', 'sources']]`

The file format to use for the apt source. See https://wiki.debian.org/SourcesList
The file format to use for the apt source. Defaults to the `apt::source_format` class parameter when omitted. `key`, `pin`, or non-empty `include` values retain the `list` format when inheriting the class default for backward compatibility. See https://wiki.debian.org/SourcesList

Default value: `'list'`
Default value: `undef`

##### <a name="-apt--source--location"></a>`location`

Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
# @param sources
# Hash of `apt::source` resources.
#
# @param source_format
# Default format for `apt::source` resources. Individual resources can override this. Defaults to `list`.
#
# @param auths
# Creates new `apt::auth` resources. Valid options: a hash to be passed to the create_resources function linked above.
#
Expand Down Expand Up @@ -241,6 +244,7 @@
'content' => undef,
'source' => undef,
},
Enum['list', 'sources'] $source_format = 'list',
) {
if $facts['os']['family'] != 'Debian' {
fail('This module only works on Debian or derivatives like Ubuntu')
Expand Down
21 changes: 15 additions & 6 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# }
#
# @param source_format
# The file format to use for the apt source. See https://wiki.debian.org/SourcesList
# The file format to use for the apt source. Defaults to the `apt::source_format` class parameter, except sources using `key`, `pin`, or
# non-empty `include` values default to `list` for backward compatibility. See https://wiki.debian.org/SourcesList
#
# @param location
# Required, unless ensure is set to 'absent'. Specifies an Apt repository. Valid options: a string containing a repository URL.
Expand Down Expand Up @@ -101,7 +102,7 @@
# Specifies whether to check if the package release date is valid.
#
define apt::source (
Enum['list', 'sources'] $source_format = 'list',
Optional[Enum['list', 'sources']] $source_format = undef,
Array[Enum['deb','deb-src'], 1, 2] $types = ['deb'],
Optional[Variant[String[1], Array[String[1]]]] $location = undef,
String[1] $comment = $name,
Expand All @@ -121,11 +122,19 @@
) {
include apt

if $source_format {
$_source_format = $source_format
} elsif ($apt::source_format == 'sources') and ($key != undef or $pin != undef or $include != {}) {
$_source_format = 'list'
} else {
$_source_format = $apt::source_format
}

$_before = Apt::Setting["list-${title}"]

case $source_format {
case $_source_format {
'list': {
$_file_suffix = $source_format
$_file_suffix = $_source_format

if !$release {
if fact('os.distro.codename') {
Expand Down Expand Up @@ -278,7 +287,7 @@
}
}
'sources': {
$_file_suffix = $source_format
$_file_suffix = $_source_format

if $pin {
warning("'pin' parameter is not supported with deb822 format.")
Expand Down Expand Up @@ -363,7 +372,7 @@
}
}
default: {
fail("Unexpected APT source format: ${source_format}")
fail("Unexpected APT source format: ${_source_format}")
}
}
apt::setting { "${_file_suffix}-${name}":
Expand Down
45 changes: 45 additions & 0 deletions spec/acceptance/apt_source_format_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'apt::source with class-level source_format' do
let(:pp) do
<<-MANIFEST
$location = $facts['os']['name'] ? {
'Debian' => 'http://deb.debian.org/debian',
default => 'http://archive.ubuntu.com/ubuntu',
}
$repos = $facts['os']['name'] ? {
'Debian' => 'contrib',
default => 'multiverse',
}

class { 'apt':
source_format => 'sources',
}

apt::source { 'format_default':
location => $location,
repos => $repos,
}

apt::source { 'format_override':
source_format => 'list',
location => $location,
repos => $repos,
}
MANIFEST
end

it 'applies idempotently' do
expect(retry_on_error_matching { idempotent_apply(pp) }).to be_truthy
end

it 'creates a deb822 file for sources inheriting the class default' do
expect(run_shell('test -f /etc/apt/sources.list.d/format_default.sources && test ! -f /etc/apt/sources.list.d/format_default.list')).to be_truthy
end

it 'honours a per-source list override' do
expect(run_shell('test -f /etc/apt/sources.list.d/format_override.list && test ! -f /etc/apt/sources.list.d/format_override.sources')).to be_truthy
end
end
7 changes: 7 additions & 0 deletions spec/classes/apt_backports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
keyring: '/usr/share/keyrings/ubuntu-archive-keyring.gpg',
)
}

context 'when the apt class defaults to deb822' do
let(:pre_condition) { 'class { "apt": source_format => "sources" }' }

it { expect(subject).to contain_apt__setting('list-backports').with_ensure('present') }
it { expect(subject).not_to contain_apt__setting('sources-backports') }
end
end

context "with everything set on ubuntu #{release_major}" do
Expand Down
38 changes: 38 additions & 0 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,44 @@
end
end

describe 'source format defaults' do
let(:params) { { location: 'http://example.test/debian' } }

context 'when the apt class defaults to deb822' do
let(:pre_condition) { 'class { "apt": source_format => "sources" }' }

it { expect(subject).to contain_apt__setting('sources-my_source').with_ensure('present') }
end

context 'when the class defaults to list and the source selects deb822' do
let(:params) { super().merge(source_format: 'sources') }

it { expect(subject).to contain_apt__setting('sources-my_source').with_ensure('present') }
end

context 'when the source explicitly selects list format' do
let(:pre_condition) { 'class { "apt": source_format => "sources" }' }
let(:params) { super().merge(source_format: 'list') }

it { expect(subject).to contain_apt__setting('list-my_source').with_ensure('present') }
end

context 'when the source uses legacy list-only options' do
let(:pre_condition) { 'class { "apt": source_format => "sources" }' }
let(:params) do
super().merge(
key: id,
pin: '10',
include: { 'src' => true },
)
end

it { expect(subject).to contain_apt__setting('list-my_source').with_content(%r{deb-src}) }
it { expect(subject).to contain_apt__pin('my_source') }
it { expect(subject).to contain_apt__key("Add key: #{id} from Apt::Source my_source") }
end
end

describe 'no defaults' do
context 'with complex pin' do
let :params do
Expand Down
Loading