Wednesday, September 05th, 2012 | Author:
Nico
Baptiste Daroussin did an incredible job on FreeBSD with the new packages system, named PkgNG. It brings modern workflow, options and shiny features that were needed for a long time. Say goodbye to painfully long upgrades.
However, Chef is not yet able to use this packaging system as it does not have a PkgNG provider, or not had. This is a hacky way to do so but here is a way to use PkgNG with chef, making it the default provider for your packages.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
require 'chef/mixin/shell_out' require 'chef/platform' require 'chef' include Chef::Mixin::ShellOut class Chef class Provider class Package class Pkgng < Chef::Provider::Package 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.debug("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
|
|
1
2
3
4
5
|
Chef::Platform.set({ :platform => :freebsd, :resource => :package, :provider => Chef::Provider::Package::Pkgng })
|
Read more : poudriere & pkgng