4

I have 3 different ways to install said package, and I prefer option #1 the most, but I wanted to see if there was a reason to use option #2 or 3 or any other options? (My goal of this question is to get feedback of different ways to do this; and not install at compile time if possible... in this case)

1st.

p = package "snmp" do
  package_name value_for_platform(
    [ "centos", "redhat", "suse" ] => { "default" => "net-snmp" },
    "default" => "snmpd"
  )
  action :install
end

2nd.

packages = case node[:platform]
  when "centos","redhat","fedora"
    %w{net-snmp}
  else
    %w{snmpd}
  end

packages.each do |pkg|
  package pkg
end

3rd.

package "snmpd" do
  action :install
  only_if do platform?("ubuntu", "debian") end
end
David Pashley
  • 23,151
  • 2
  • 41
  • 71
Scott M Likens
  • 201
  • 1
  • 3

1 Answers1

6

I typically don't support too many distros in my own recipes, but when reading other recipes (such as from Opscode) I generally appreciate approaches similar to your second, above, the main difference is that I would tend to explicitly invoke the resource directly, rather than compile an array.

case node[:platform]
when "centos","redhat","fedora"
  package 'net-snmp'
else
  package 'snmpd'
end

However, there are a number of pros and cons for each case, depending on what exactly you're trying to express.

Nick Zadrozny
  • 201
  • 1
  • 3