Listing chef-installed software packages


#1

Is there any way, from within a recipe, to obtain an array of all the
system packages (e.g. via apt on debian) or ruby gems explicitly
installed on the node as a result of the node’s current run list?

Thanks.


#2

On 07/04/2011 10:13 PM, Lee Maguire wrote:

Is there any way, from within a recipe, to obtain an array of all the
system packages (e.g. via apt on debian) or ruby gems explicitly
installed on the node as a result of the node’s current run list?

Thanks.

I dont know if there’s any clean way to do that, as the ruby gems or deb
package dependency is managed via apt or gem (the package manager
itself), other wise you can always two execute statements , one
beginning of the recipe gem list > before.gems and dpkg --get-selections> before.debs and one end of the recipe gem list > after.gems and dpkg --get-selections> after.debs and then use a
report handler to get the diff and process it further.

hope this helps
regards
ranjib


#3

Is there any way, from within a recipe, to obtain an array of all the
system packages (e.g. via apt on debian) or ruby gems explicitly
installed on the node as a result of the node’s current run list?

I don’t know if there’s any clean way to do that, as the ruby gems or
deb package dependency is managed via apt or gem (the package manager
itself)

I’m not interested in the dependencies, just those that have been
explicitly installed by recipes (i.e. as the package resource).


#4

On 07/04/2011 10:40 PM, Lee Maguire wrote:

Is there any way, from within a recipe, to obtain an array of all the
system packages (e.g. via apt on debian) or ruby gems explicitly
installed on the node as a result of the node’s current run list?
I don’t know if there’s any clean way to do that, as the ruby gems or
deb package dependency is managed via apt or gem (the package manager
itself)
I’m not interested in the dependencies, just those that have been
explicitly installed by recipes (i.e. as the package resource).

aha… then its easy, you can use any report handlers, the report method
invoked with a run_status object which contain updated_resources object,
which is actually a resource collection; you can use this collection
and filter out only the packages that are updated or installed.
regards
ranjib

http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers


#5

aha… then its easy, you can use any report handlers, the report method
invoked with a run_status object which contain updated_resources object,
which is actually a resource collection; you can use this collection
and filter out only the packages that are updated or installed.

So the only way to access this information is adding report handlers to
client.rb - it can’t be done from within cookbooks?

I’m trying to automatically populate the deborphan “keep” file with
packages that have been installed by chef.


module Deborphan
class Keep < ::Chef::Handler
attr_reader :config
def initialize(config={})
@config = config
@config[:keepfile] ||= "/var/lib/deborphan/keep"
end
def report
File.open(config[:keepfile],‘w’) do |keep|
run_status.all_resources.each do |r|
if (r.resource_name.to_s == ‘package’) && (r.action.to_s ==
‘install’ ) then
keep.puts r.package_name.to_s
end
end
end
end
end
end


#6

On Tue, Jul 5, 2011 at 8:31 AM, Lee Maguire lee-lists@dxw.com wrote:

aha… then its easy, you can use any report handlers, the report method
invoked with a run_status object which contain updated_resources object,
which is actually a resource collection; you can use this collection
and filter out only the packages that are updated or installed.

So the only way to access this information is adding report handlers to
client.rb - it can’t be done from within cookbooks?

I’m trying to automatically populate the deborphan “keep” file with
packages that have been installed by chef.

You can do the same by just enumerating the resource collection within
a recipe, and checking each resources updated? status.

That said, doing it in a report handler is probably better - it will
make sure you always catch any installed/updated packages, even in the
case of a recipe aborting with an error.

Best,
Adam


Opscode, Inc.
Adam Jacob, Chief Product Officer
T: (206) 619-7151 E: adam@opscode.com


#7

But I think Lee was asking whether he had to use client.rb to populate the
report_handlers - and as far as I understood from
http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers, you can
do that from a recipe by using the chef_handler LWRP.

Is that right?

On Tue, Jul 5, 2011 at 6:43 PM, Adam Jacob adam@opscode.com wrote:

On Tue, Jul 5, 2011 at 8:31 AM, Lee Maguire lee-lists@dxw.com wrote:

So the only way to access this information is adding report handlers to
client.rb - it can’t be done from within cookbooks?

I’m trying to automatically populate the deborphan “keep” file with
packages that have been installed by chef.

You can do the same by just enumerating the resource collection within
a recipe, and checking each resources updated? status.

That said, doing it in a report handler is probably better - it will
make sure you always catch any installed/updated packages, even in the
case of a recipe aborting with an error.

Best,
Adam


Opscode, Inc.
Adam Jacob, Chief Product Officer
T: (206) 619-7151 E: adam@opscode.com

Tim Diggins
http://red56.co.uk
tim@red56.co.uk

07515 931 642 / +447515931642