4

I have a chef recipe that can either run on virtual machines or real machines. I need to be able to tell the difference between them inside chef, because I need to treat them differently. I've found something on the internet that said I should just use

if node[:instance_role] == 'vagrant'

but that doesn't seem to work for me. node[:instance_role] is just blank.

Do you know any other way of doing it?

I'm using chef_solo with vagrant provisioning

  • I have never check that, but create both of them as node and compare node attributes. But @coderanger answer looks promising. – Lukino Sep 19 '14 at 19:15

1 Answers1

5

Look under node['virtualization'] for information about the VM runtime. Vagrant isn't actually a VM system though, so you won't see anything about that. A better option for Vagrant-specific behavior is to set a node attribute in your Vagrantfile and reference that in your recipe code.

coderanger
  • 52,400
  • 4
  • 52
  • 75