puppetlabs/puppet · error · Puppet::Error

/etc/apt/sources.list contains a cdrom source; not installin

Error message

/etc/apt/sources.list contains a cdrom source; not installing.  Use 'allowcdrom' to override this failure.

What it means

The apt provider's checkforcdrom (apt.rb:93) reads /etc/apt/sources.list and, if any non-commented line contains 'cdrom:', aborts the install with Puppet::Error unless the package resource sets allowcdrom => :true. It guards against unattended installs silently prompting for a CD-ROM disc that is not present.

Source

Thrown at lib/puppet/provider/package/apt.rb:93

  end

  # A derivative of DPKG; this is how most people actually manage
  # Debian boxes, and the only thing that differs is that it can
  # install packages from remote sites.

  # Double negation confuses Rubocop's Layout cops
  # rubocop:disable Layout
  def checkforcdrom
    have_cdrom = begin
                   !!(File.read("/etc/apt/sources.list") =~ /^[^#]*cdrom:/)
                 rescue
                   # This is basically pathological...
                   false
                 end
  # rubocop:enable Layout

    if have_cdrom and @resource[:allowcdrom] != :true
      raise Puppet::Error, _("/etc/apt/sources.list contains a cdrom source; not installing.  Use 'allowcdrom' to override this failure.")
    end
  end

  def best_version(should_range)
    versions = []

    output = aptcache :madison, @resource[:name]
    output.each_line do |line|
      is = line.split('|')[1].strip
      begin
        is_version = DebianVersion.parse(is)
        versions << is_version if should_range.include?(is_version)
      rescue DebianVersion::ValidationFailure
        Puppet.debug("Cannot parse #{is} as a debian version")
      end
    end

    return versions.max if versions.any?

View on GitHub (pinned to e227c27540)

Solutions

  1. Comment out or remove the `deb cdrom:...` line in /etc/apt/sources.list (usually the right fix — cdrom entries rarely belong on managed servers).
  2. If the cdrom source is intentional, opt in per resource: `package { 'foo': ensure => installed, allowcdrom => true }`.
  3. Replace the cdrom entry with a real network mirror and run apt-get update.

Example fix

# before
# /etc/apt/sources.list:  deb cdrom:[Debian...]/ stable main
package { 'htop': ensure => installed }

# after (sources.list):  # deb cdrom:[Debian...]/ stable main
#   deb http://deb.debian.org/debian stable main
package { 'htop': ensure => installed }
Defensive patterns

Strategy: validation

Validate before calling

# fail fast with a clear message before apt runs
cdrom = File.read('/etc/apt/sources.list') =~ /^[^#]*cdrom:/ rescue nil
allow = resource[:allowcdrom] == :true
raise 'cdrom source active; pass allowcdrom or fix sources.list' if cdrom && !allow

Try / catch

begin
  provider.install
rescue Puppet::Error => e
  raise unless e.message.include?('allowcdrom')
  # retry once with explicit consent flag set
  resource[:allowcdrom] = :true; retry
end

Prevention

When it happens

Trigger: Any ensure => installed/present on a package using the apt provider on a system where /etc/apt/sources.list still contains an active `deb cdrom:...` line and the resource does not set allowcdrom. The file read is wrapped in a rescue (missing file counts as no cdrom), so only the combination cdrom-line + no allowcdrom triggers it.

Common situations: Debian installed from CD/DVD/ISO media whose sources.list still lists the cdrom entry; offline mirror setups cloned from a media install; minimal containers based on installer images.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/a49e72386b85acc7. Report an issue: GitHub.