Skip to content

Commit

Permalink
Add support for deb822 APT sources (#1167)
Browse files Browse the repository at this point in the history
* Initial testing for deb822 APT sources

* Added defined type for generating deb822 apt sources

Should be roughly drop-in alternative to the existing apt::source type
Does not currently support inline ascii gpg key

* Add puppet strings documentation

* Replace example with generic content

* Initial testing of apt::source with deb822 support

* Fix setting_type and signed_by

Use 'sources' instead of 'source' as the setting_type parsed to
apt::setting

Fix the data type of apt::source::signed_by

* Fix source_deb822.epp template

Correctly handle newline/whitespace trimming for `signed_by` parameter.

* Remove link from components to repos

* Add logic for deb822 sources

* Update documentation for deb822 sources

* Update source_format parameter

Match the possible values to the file suffix of the created source
files.

* Add forward-compatibility with deb822

Allow array values for certain parameters to allow easy switching between .list and .sources formats.

* Add backward-compatibility for deb822 sources

Convert string values to arrays where possible and warn the user.

* Fix logic

* Revert "Add forward-compatibility with deb822"

This reverts commit 9d88e93.

* Fix deb822 backward compatibility

Correctly compare data type when generating deb822 sources
Remove unused class parameters and descriptions

* Update puppet-strings and logic

Remove references to unused deb822 parameters
Update parameter descriptions
Update deb822 example
Update warnings for $pin and $key usage with deb822. Currently
unsupported
Don't fail if $location is missing unless $ensure is 'present'

* Remove unused spec test

* Add unit testing for deb822 sources

* Update README.md with deb822 sources example

* Fix unit test syntax

* Re-apply commit 2faa817

eliminate params.pp and create_resources()

params.pp and create_resources() are obsolete.

This module was converted to non-params.pp style #667, but was
reverted in #680. Using Hiera in modules and no params.pp are the
preferred styles these days.

* Update apt::config_files hash

Add support for deb822 .sources files

* Update data types and documentation

Re-apply data-type changes for apt::source::pin from 1e1baad
Regenerate puppet strings to match.

* Update source_deb822.epp template

Remove leading whitespace

* Update manifests/setting.pp

Simplify apt::setting logic

Co-authored-by: Tim Meusel <[email protected]>

---------

Co-authored-by: James Paton-Smith <[email protected]>
Co-authored-by: Tim Meusel <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent 30e8065 commit 9876c31
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 154 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ apt::source { 'puppetlabs':

<a id="configure-apt-from-hiera"></a>

### Generating a DEB822 .sources file

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.
```puppet
apt::source { 'debian':
source_format => 'sources'
comment => 'Official Debian Repository',
enabled => true,
types => ['deb', 'deb-src'],
location => ['http://fr.debian.org/debian', 'http://de.debian.org/debian']
release => ['stable', 'stable-updates', 'stable-backports'],
repos => ['main', 'contrib', 'non-free'],
architecture => ['amd64', 'i386'],
allow_unsigned => true,
keyring => '/etc/apt/keyrings/debian.gpg'
notify_update => false
}
```

### Configure Apt from Hiera

Instead of specifying your sources directly as resources, you can instead just include the `apt` class, which will pick up the values automatically from hiera.
Expand Down
68 changes: 57 additions & 11 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ Default value:
'path' => $sources_list_d,
'ext' => '.list',
},
'sources' => {
'path' => $sources_list_d,
'ext' => '.sources',
},
}
```

Expand Down Expand Up @@ -1088,11 +1092,25 @@ apt::source { 'puppetlabs':
}
```

##### Install the puppetlabs apt source (deb822 format)

```puppet
apt::source { 'puppetlabs':
source_format => 'sources'
location => ['http://apt.puppetlabs.com'],
repos => ['puppet8'],
keyring => '/etc/apt/keyrings/puppetlabs.gpg',
}
```

#### Parameters

The following parameters are available in the `apt::source` defined type:

* [`source_format`](#-apt--source--source_format)
* [`location`](#-apt--source--location)
* [`types`](#-apt--source--types)
* [`enabled`](#-apt--source--enabled)
* [`comment`](#-apt--source--comment)
* [`ensure`](#-apt--source--ensure)
* [`release`](#-apt--source--release)
Expand All @@ -1107,14 +1125,39 @@ The following parameters are available in the `apt::source` defined type:
* [`notify_update`](#-apt--source--notify_update)
* [`check_valid_until`](#-apt--source--check_valid_until)

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

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

The file format to use for the apt source. See https://wiki.debian.org/SourcesList

Default value: `'list'`

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

Data type: `Optional[String[1]]`
Data type: `Optional[Variant[String[1], Array[String[1]]]]`

Required, unless ensure is set to 'absent'. Specifies an Apt repository.
Required, unless ensure is set to 'absent'. Specifies an Apt repository. Valid options: a string containing a repository URL.
DEB822: Supports an array of URL values

Default value: `undef`

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

Data type: `Array[Enum['deb','deb-src'], 1, 2]`

DEB822: The package types this source manages.

Default value: `['deb']`

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

Data type: `Boolean`

DEB822: Enable or Disable the APT source.

Default value: `true`

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

Data type: `String[1]`
Expand All @@ -1133,17 +1176,19 @@ Default value: `present`

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

Data type: `Optional[String[0]]`
Data type: `Optional[Variant[String[0], Array[String[0]]]]`

Specifies a distribution of the Apt repository.
DEB822: Supports an array of values

Default value: `undef`

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

Data type: `String[1]`
Data type: `Variant[String[1], Array[String[1]]]`

Specifies a component of the Apt repository.
DEB822: Supports an array of values

Default value: `'main'`

Expand Down Expand Up @@ -1194,29 +1239,30 @@ Default value: `undef`

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

Data type: `Optional[String[1]]`
Data type: `Optional[Variant[String[1], Array[String[1]]]]`

Tells Apt to only download information for specified architectures. Valid options: a string containing one or more architecture names,
separated by commas (e.g., 'i386' or 'i386,alpha,powerpc').
(if unspecified, Apt downloads information for all architectures defined in the Apt::Architectures option)
DEB822: Supports an array of values

Default value: `undef`

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

Data type: `Boolean`
Data type: `Optional[Boolean]`

Specifies whether to authenticate packages from this release, even if the Release file is not signed or the signature can't be checked.

Default value: `false`
Default value: `undef`

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

Data type: `Boolean`
Data type: `Optional[Boolean]`

Specifies whether to allow downloads from insecure repositories.

Default value: `false`
Default value: `undef`

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

Expand All @@ -1228,11 +1274,11 @@ Default value: `true`

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

Data type: `Boolean`
Data type: `Optional[Boolean]`

Specifies whether to check if the package release date is valid.

Default value: `true`
Default value: `undef`

## Data types

Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@
'path' => $sources_list_d,
'ext' => '.list',
},
'sources' => {
'path' => $sources_list_d,
'ext' => '.sources',
},
},
Boolean $sources_list_force = false,
Hash $source_key_defaults = {
Expand Down
6 changes: 3 additions & 3 deletions manifests/setting.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
$setting_type = $title_array[0]
$base_name = join(delete_at($title_array, 0), '-')

assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/], $setting_type) |$a, $b| {
fail("apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/, /\Asources\z/], $setting_type) |$a, $b| {
fail("apt::setting resource name/title must start with either 'conf-', 'pref-', 'list-', or 'sources-'")
}

if $priority !~ Integer {
Expand All @@ -51,7 +51,7 @@
}
}

if ($setting_type == 'list') or ($setting_type == 'pref') {
if $setting_type in ['list', 'pref', 'sources'] {
$_priority = ''
} else {
$_priority = $priority
Expand Down
Loading

0 comments on commit 9876c31

Please sign in to comment.