Cristian Vasile
Cristian Vasile

Reputation: 101

How can you tell if chef is running on a VM (i.e. vagrant)

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

Upvotes: 4

Views: 1449

Answers (1)

coderanger
coderanger

Reputation: 54211

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.

Upvotes: 5

Related Questions