I have a Chef (solo) recipe which generates a CSS file and puts it somewhere into web root directory (/vagrant/css
on VM in my case). The problem is that the recipe needs to know an absolute path to vagrant synced directory on VM - it is a folder where Vagrantfile
is, and by default it maps to /vagrant
inside a VM.
I know how to set that path:
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/synced/dir/on/vm"
end
But the problem is how to let the recipe know that /synced/dir/on/vm
.
Currently I use that:
Vagrant.configure("2") do |config|
config.vm.provision :chef_solo do |chef|
chef.json = {
"base_directory" => "/vagrant" # THIS IS IT
}
end
end
It lets me use node["base_directory"]
inside the recipe code, but there is a downside to that: if I was to write multiple recipes, it would be inconvinient to use node["base_directory"]
in every recipe. It is much better that hardcoding the path, but it forces me to use same key on chef.json
for every recipe.
Furthermore, if I'd wish to share my recipe, I would force users to use that "base_directory" => "/vagrant"
key/value pair in their Vagrantfile
.
Is there an API method to get this synched directory path on VM in the recipe code? Or more genarally: is there a way to get Vagrant-specific properties from Chef recipes?
I scoured Vagrant docs, but there seems to be just a single page on that topic, and because it is specific to Vagrant, there is no related information in Chef docs either.
node
object – sethvargo