Skip to content

Add class-level source_format default for apt::source - relates to issue #1268 - #1340

Open
Phil-Friderici wants to merge 1 commit into
puppetlabs:mainfrom
Phil-Friderici:feature/class-level-source-format
Open

Phil-Friderici wants to merge 1 commit into
puppetlabs:mainfrom
Phil-Friderici:feature/class-level-source-format

Conversation

@Phil-Friderici

Copy link
Copy Markdown

Summary

Adds an apt::source_format class parameter (default: list) that supplies the format for apt::source resources that do not set source_format themselves. A format set on an individual resource still takes precedence. deb822 (.sources) can now be enabled for all sources with one setting:

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

apt::source::source_format now defaults to undef and inherits the class value. Sources that use key, pin or a non-empty include (not supported by the deb822 format) keep the list format when inheriting the default, so existing declarations and apt::backports behave as before.

The default stays list, so nothing changes unless the parameter is set. README and REFERENCE are updated.

Additional Context

  • Root cause and the steps to reproduce.
    Since Ubuntu 25.10 only the deb822 format is supported, but apt::source always defaults to list, so source_format has to be set on every resource. Apt::Source { source_format => 'sources' } only works in the current scope and does not reach other modules.
  • Thought process behind the implementation.
    A class-level opt-in is explicit and has no impact on existing catalogs. Automatic selection by OS release was not chosen because it would change the generated files (and leave the old .list files behind) on upgrade without the user asking for it. Making the default OS-dependent can be done later by changing the default of the new parameter.

Related Issues (if any)

Relates to #1268.

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

Validation

Command Result
bundle exec rake parallel_spec passed, 523 examples, 0 failures
bundle exec rubocop on the changed spec files passed, no offenses
Litmus docker_ub_6 (Ubuntu 18.04, 20.04, 22.04, 24.04) passed, 49 examples, 0 failures, 5 pending (apt_key_missing_spec, apt-key is available) each
Litmus docker_ub_6 (Ubuntu 26.04) not run: Puppet Core 8 provides no puppet8-release-resolute.deb (HTTP 404), the agent cannot be installed

Not tested: Debian 11/12/13 and a manual puppet apply.

Relates to puppetlabs#1268.

Add an `apt::source_format` class parameter (default: `list`) that
supplies the format for `apt::source` resources which do not set
`source_format` themselves. A format set on an individual resource
still takes precedence, so deb822 (`sources`) can be enabled for all
sources with a single setting:

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

`apt::source::source_format` now defaults to `undef` and inherits the
class value. Sources that use `key`, `pin` or a non-empty `include`
(all unsupported by the deb822 format) keep the `list` format when
inheriting the default, so existing declarations and `apt::backports`
behave as before.

The default stays `list`, so there is no behavior change unless the
parameter is set.

Tests:
- unit: inheritance, per-resource override in both directions, legacy
  options falling back to `list`, `apt::backports` staying on `list`
- acceptance: the class default yields a `.sources` file and a
  per-source override keeps `.list`

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jst-cyr

jst-cyr commented Nov 19, 2026

Copy link
Copy Markdown
Member

Thanks for the PR @Phil-Friderici , I'll kick off some acceptance testing to get you some platform testing feedback on this one.

@jst-cyr

jst-cyr commented Nov 19, 2026

Copy link
Copy Markdown
Member

Tests are being executed for this PR in #1342

@jst-cyr

jst-cyr commented Nov 19, 2026

Copy link
Copy Markdown
Member

Hey @Phil-Friderici, while the tests are running, I did a little digging into some potentially overlapping work in some other PRs.

This class-level default is a good way to handle #1268, especially because it also reaches apt::source resources declared in other modules. We might want to wait on a few other PRs and pull those down into this:

I'll queue this up for review to be after those other PRs so that we'll be able to pull those down before this goes in. Once they are merged up, this PR can be rebased/merged/updated.

@jst-cyr

jst-cyr commented Nov 19, 2026

Copy link
Copy Markdown
Member

🛑 Acceptance Test Results: https://github.com/puppetlabs/puppetlabs-apt/actions/runs/44435400752?pr=1342

Most platforms are fine, but Debian 12 is failing for both Puppet Core 8 and Puppet Core 9 with the same issue in the new acceptance test. I pointed Claude Code at the errors and PR changes to get a first analysis of the failure and root cause:

From 🤖 Claude Code:

Failure

  • Both jobs fail on one test, spec/acceptance/apt_source_format_spec.rb:34, "applies idempotently". The other 48 examples pass.
  • The puppet apply exits with code 4 on all 10 retries. The two jobs differ only in Ruby and stack-trace paths.
  • The error is: Could not prefetch package provider 'apt': apt-mark showmanual returned 100: E: Conflicting values set for option Signed-By regarding source http://deb.debian.org/debian/ bookworm: /usr/share/keyrings/debian-archive-keyring.gpg != <empty>
  • Because of that error, apt can't read its sources at all, so Package[gnupg] is skipped.

Root cause

  • The test declares apt::source { 'format_default': location => 'http://deb.debian.org/debian', repos => 'contrib' } with the class default source_format => 'sources'.
  • That writes /etc/apt/sources.list.d/format_default.sources for http://deb.debian.org/debian and suite bookworm, with no Signed-By: line. The template only emits it when keyring is set (source.pp:360).
  • Debian 12 images already ship /etc/apt/sources.list.d/debian.sources for the same URI and suite, and it has Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg.
  • apt rejects two entries for the same URI and suite when their Signed-By values differ. I inferred the pre-existing debian.sources from the error message. I didn't check the CI image directly.
  • The 'format_override' source in the same test has the same URI and suite in .list format, so it likely has the same problem. I didn't confirm that.

Summary:

  • Both Debian 12 jobs fail on apt_source_format_spec.rb:34 for one reason: the test duplicates Debian's own deb.debian.org/debian bookworm source without a Signed-By, and apt refuses to read its sources.
  • The module code isn't shown to be wrong here. The deb822 output is valid, and the default stays list.
  • Suggested fixes, easiest first:
    • Use a repo that Debian doesn't already configure, such as a different location or suite.
    • Pass keyring => '/usr/share/keyrings/debian-archive-keyring.gpg' to both test sources on Debian.
    • Remove the pre-existing debian.sources in a before step. This is the most invasive option.
  • Other platforms may hit the same clash. Ubuntu 24.04 also ships a ubuntu.sources with Signed-By. I didn't check the other jobs' results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants