Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.