Kevin Burke
Kevin Burke

Reputation: 64756

In Chef how do I detect if chef is running on a Mac?

In my cookbooks, how should I check if the chef recipe is being provisioned onto a Macintosh machine?

Upvotes: 1

Views: 1245

Answers (2)

Mark O'Connor
Mark O'Connor

Reputation: 77951

A better solution is to use a platform_family check. Will work for both OS X and OS X server (Source OHAI-345).

cookbook_file "/etc/nginx/nginx.conf" do
  source "nginx.conf"
  not_if platform_family?("mac_os_x")
end

An even better solution would be to let chef do all the work. Use a single cookbook_file declaration:

cookbook_file "/etc/nginx/nginx.conf" do
  source "nginx.conf"
end

And ship the platform specific files with your cookbook:

  • mycookbook/files/default/nginx.conf
  • mycookbook/files/mac_os_x/nginx.conf
  • mycookbook/files/ubuntu/nginx.conf
  • ..

Upvotes: 5

Kevin Burke
Kevin Burke

Reputation: 64756

Use

node[:platform] == "mac_os_x" 

to check.

You can do a not_if block like this:

cookbook_file "/etc/nginx/nginx.conf" do
     source "nginx.conf"
     not_if { node[:platform] == "mac_os_x" }
end

Upvotes: 1

Related Questions