Created
September 4, 2012 11:09
-
-
Save rottenbytes/3620234 to your computer and use it in GitHub Desktop.
package provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chef/mixin/command' | |
require 'chef/log' | |
require 'chef/file_cache' | |
require 'chef/platform' | |
require 'chef' | |
class Chef | |
class Provider | |
class Package | |
class Pkgng < Chef::Provider::Package | |
include Chef::Mixin::ShellOut | |
def initialize(*args) | |
super | |
@current_resource = Chef::Resource::Package.new(@new_resource.name) | |
@current_resource.package_name(@new_resource.package_name) | |
@current_resource | |
end | |
def check_package_state | |
pkg_info = shell_out!("pkg info #{package_name}", :env => nil, :returns => [0,70]) | |
version = nil | |
t = pkg_info.stdout.match(/(.*)-(\d+\.\d+\.\d+(\.\d+.*\s)?)\s+(.*)/) | |
unless t.nil? | |
version = t[2].strip | |
end | |
return version | |
end | |
def load_current_resource | |
@current_resource.package_name(@new_resource.package_name) | |
@current_resource.version(self.check_package_state()) | |
@candidate_version = "" | |
end | |
def package_name | |
@new_resource.package_name | |
end | |
def install_package(name, version = "") | |
shell_out!("pkg install -y #{package_name}", :env => nil).status | |
Chef::Log.info("PKGNG : #{@new_resource} installed from: #{@new_resource.source}") | |
end | |
def remove_package(name, version = nil) | |
shell_out!("pkg delete -y #{package_name}", :env => nil).status | |
end | |
end | |
end | |
end | |
end | |
Chef::Platform.platforms[:freebsd][:default][:package] = Chef::Provider::Package::Pkgng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
[Tue, 04 Sep 2012 13:10:33 +0200] INFO: Storing updated cookbooks/os/providers/package/pkgng.rb in the cache. | |
[Tue, 04 Sep 2012 13:10:33 +0200] ERROR: Running exception handlers | |
[Tue, 04 Sep 2012 13:10:33 +0200] FATAL: Saving node information to /var/cache/chef/backup/failed-run-data.json | |
[Tue, 04 Sep 2012 13:10:33 +0200] ERROR: Exception handlers complete | |
[Tue, 04 Sep 2012 13:10:33 +0200] FATAL: Stacktrace dumped to /var/cache/chef/backup/chef-stacktrace.out | |
[Tue, 04 Sep 2012 13:10:33 +0200] FATAL: NameError: uninitialized constant #<Class:0x00000804591df0>::Chef::Mixin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment