puppetlabs/puppet · error · Puppet::Error

puppet:// URLs are not supported as gem sources

Error message

puppet:// URLs are not supported as gem sources

What it means

puppetserver_gem's install parses resource[:source] as a URI and explicitly rejects the 'puppet://' scheme - gems cannot be fetched from Puppet's fileserver. The error is raised before any gem command runs, so it is purely a manifest configuration error, not an execution failure.

Source

Thrown at lib/puppet/provider/package/puppetserver_gem.rb:107

    command_options << '--no-document'

    if resource[:source]
      begin
        uri = URI.parse(resource[:source])
      rescue => detail
        self.fail Puppet::Error, _("Invalid source '%{uri}': %{detail}") % { uri: uri, detail: detail }, detail
      end

      case uri.scheme
      when nil
        # no URI scheme => interpret the source as a local file
        command_options << resource[:source]
      when /file/i
        command_options << uri.path
      when 'puppet'
        # we don't support puppet:// URLs (yet)
        raise Puppet::Error, _('puppet:// URLs are not supported as gem sources')
      else
        # interpret it as a gem repository
        command_options << '--source' << resource[:source].to_s << resource[:name]
      end
    else
      command_options << resource[:name]
    end

    output = puppetservercmd(command_options)
    # Apparently, some gem versions don't exit non-0 on failure.
    self.fail _("Could not install: %{output}") % { output: output.chomp } if output.include?('ERROR')
  end

  def uninstall
    command_options = %w[gem uninstall]
    command_options << '--executables' << '--all' << resource[:name]
    command_options += uninstall_options if resource[:uninstall_options]

View on GitHub (pinned to e227c27540)

Solutions

  1. Serve the .gem over HTTP(S) or from a local path and point source at that: source => '/opt/gems/x-1.0.gem' or 'https://mirror.example/gems'
  2. If the gem must come from the module, stage it with a file resource to a local path first, then reference that path as the package source with require =>
  3. Drop the source attribute entirely to install from the default gem repositories

Example fix

// before
package { 'json-jruby':
  ensure   => '1.8.3',
  provider => puppetserver_gem,
  source   => 'puppet:///modules/profile/gems/json-1.8.3.gem',
}
// after - stage the gem locally, then install from the file path
file { '/opt/gems/json-1.8.3.gem':
  ensure => file,
  source => 'puppet:///modules/profile/gems/json-1.8.3.gem',
}
package { 'json-jruby':
  ensure   => '1.8.3',
  provider => puppetserver_gem,
  source   => '/opt/gems/json-1.8.3.gem',
  require  => File['/opt/gems/json-1.8.3.gem'],
}
Defensive patterns

Strategy: validation

Validate before calling

require 'uri'
# Ruby: reject sources the puppetserver_gem provider cannot use, before catalog application
def supported_gem_source?(source)
  scheme = URI.parse(source).scheme
  scheme.nil? || scheme =~ /\Afile\z/i || %w[http https].include?(scheme)
rescue URI::InvalidURIError
  false
end

Type guard

# Narrows a source string to the shapes puppetserver_gem accepts (local path, file://, http(s)://)
GEM_SOURCE_SHAPE = %r{\A(/|file://|https?://)}
def gem_source?(value)
  value.is_a?(String) && !value.start_with?('puppet://') && GEM_SOURCE_SHAPE.match?(value)
end

Try / catch

begin
  provider.install
rescue Puppet::Error => e
  raise unless e.message =~ /puppet:\/\/ URLs are not supported/
  raise Puppet::Error, "#{resource[:name]}: stage the gem locally (file resource) instead of puppet://"
end

Prevention

When it happens

Trigger: package { 'x': provider => puppetserver_gem, source => 'puppet:///modules/gems/x-1.0.gem' } - URI.parse yields scheme 'puppet' and the case at lib/puppet/provider/package/puppetserver_gem.rb:105 raises immediately.

Common situations: Users assuming package sources behave like file resource sources; copying puppet:// patterns that work for rpm/deb file sources; module examples reusing module-path URLs for gems.

Related errors


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