Skip to content

Instantly share code, notes, and snippets.

@jclay
Created October 3, 2013 17:10
Show Gist options
  • Save jclay/6813362 to your computer and use it in GitHub Desktop.
Save jclay/6813362 to your computer and use it in GitHub Desktop.
Detecting whether you're running Vagrant in your Chef attributes file

I wanted to have a way to specify some attributes based on whether or not I was running in Vagrant. According to other resources on the web it looks like Vagrant used to set the vagrant attribute for us but no longer does so we need to manually specify it.

Vagrantfile

  ...
    config.vm.provision :chef_solo do |chef|
      chef.json = {
        vagrant: true 
      }
      chef.run_list = [
          "recipe[my_site::default]"
      ]
    end
  ...

Your Chef attributes file

if node.attribute?('vagrant')
  default['openssh']['server']['port']                              = "22"	
else
	default['openssh']['server']['port']                              = "8437"	
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment