Skip to content

Commit 04b789d

Browse files
committed
Example of a simple puppet package provider wrapper
Allows basic actions to be taken without tying your commands to the local package manager.
1 parent 7ef4a6a commit 04b789d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

puppet-pkg

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/ruby
2+
require 'puppet'
3+
4+
# simple example of using a puppet type and providers
5+
# to hide implementation details.
6+
# This script isn't that robust.
7+
8+
pkg_action = ARGV.shift
9+
pkg_name = ARGV.shift
10+
11+
# ppp = instance of the puppet package provider
12+
ppp = Puppet::Type.type(:package).new(:name => pkg_name).provider
13+
14+
case pkg_action
15+
when "remove", "delete", "uninstall"
16+
ppp.purge
17+
when "install"
18+
ppp.install
19+
when "update", "upgrade"
20+
ppp.update
21+
when "status"
22+
if ppp.properties[:ensure] == :absent
23+
puts "Failed to find #{pkg_name}"
24+
else
25+
puts pkg_name
26+
ppp.properties.each_pair do |k,v|
27+
puts " - #{k} => #{v}"
28+
end
29+
end
30+
else
31+
puts "Don't know how to '#{pkg_action}'"
32+
exit 1
33+
end

0 commit comments

Comments
 (0)