Skip to content

Commit

Permalink
Merge pull request puppetlabs#3784 from branan/pup-4237/add_agent_gem…
Browse files Browse the repository at this point in the history
…_provider

(PUP-4237) Add puppet_gem provider (take 2)
  • Loading branch information
Kylo Ginsberg committed Apr 2, 2015
2 parents 74e90cc + 2fe9f51 commit a5324c3
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 145 deletions.
25 changes: 19 additions & 6 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 @@ -54,12 +55,12 @@ def self.gemsplit(desc)
# so we don't need to check for them

if desc =~ /^(\S+)\s+\((.+)\)/
name = $1
gem_name = $1
versions = $2.split(/,\s*/)
{
:name => name,
:name => gem_name,
:ensure => versions.map{|v| v.split[0]},
:provider => :gem
:provider => name
}
else
Puppet.warning "Could not match #{desc}" unless desc.chomp.empty?
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

0 comments on commit a5324c3

Please sign in to comment.