Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-4237) Add puppet-agent gem provider #3777

Merged
19 changes: 16 additions & 3 deletions lib/puppet/provider/package/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
interpreted as the path to a local gem file. If source is not present at all,
the gem will be installed from the default gem repositories.

This provider supports the `install_options` attribute, which allows command-line flags to be passed to the gem command.
This provider supports the `install_options` and `uninstall_options` attributes,
which allow command-line flags to be passed to the gem command.
These options should be specified as a string (e.g. '--flag'), a hash (e.g. {'--flag' => 'value'}),
or an array where each element is either a string or a hash."

has_feature :versionable, :install_options
has_feature :versionable, :install_options, :uninstall_options

commands :gemcmd => "gem"

Expand Down Expand Up @@ -122,7 +123,15 @@ def query
end

def uninstall
gemcmd "uninstall", "-x", "-a", resource[:name]
command = [command(:gemcmd), "uninstall"]
command << "--executables" << "--all" << resource[:name]

command += uninstall_options if resource[:uninstall_options]

output = execute(command)

# Apparently some stupid gem versions don't exit non-0 on failure
self.fail "Could not uninstall: #{output.chomp}" if output.include?("ERROR")
end

def update
Expand All @@ -132,4 +141,8 @@ def update
def install_options
join_options(resource[:install_options])
end

def uninstall_options
join_options(resource[:uninstall_options])
end
end
17 changes: 17 additions & 0 deletions lib/puppet/provider/package/puppet_gem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'puppet/provider/package'

Puppet::Type.type(:package).provide :puppet_gem, :parent => :gem do
desc "Puppet Ruby Gem support. This provider is useful for managing
gems needed by the ruby provided in the puppet-agent package."

has_feature :versionable, :install_options, :uninstall_options

if Puppet.features.microsoft_windows?
# On windows, we put our ruby ahead of anything that already
# existed on the system PATH. This means that we do not need to
# sort out the absolute path.
commands :gemcmd => "gem"
else
commands :gemcmd => "/opt/puppetlabs/puppet/bin/gem"
end
end
Loading