Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically get Vagrant property in Chef solo recipe
    primarykey
    data
    text
    <p>I have a Chef (solo) recipe which generates a CSS file and puts it somewhere into web root directory (<code>/vagrant/css</code> 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 <code>Vagrantfile</code> is, and by default it maps to <code>/vagrant</code> inside a VM.</p> <p>I know <a href="http://docs.vagrantup.com/v2/synced-folders/basic_usage.html" rel="nofollow">how to set that path</a>:</p> <pre class="lang-ruby prettyprint-override"><code>Vagrant.configure("2") do |config| config.vm.synced_folder ".", "/synced/dir/on/vm" end </code></pre> <p>But the problem is how to let the recipe know that <code>/synced/dir/on/vm</code>.</p> <p>Currently I use that:</p> <pre class="lang-ruby prettyprint-override"><code>Vagrant.configure("2") do |config| config.vm.provision :chef_solo do |chef| chef.json = { "base_directory" =&gt; "/vagrant" # THIS IS IT } end end </code></pre> <p>It lets me use <code>node["base_directory"]</code> inside the recipe code, but there is a downside to that: if I was to write multiple recipes, it would be inconvinient to use <code>node["base_directory"]</code> in every recipe. It is much better that hardcoding the path, but it forces me to use same key on <code>chef.json</code> for every recipe.</p> <p>Furthermore, if I'd wish to share my recipe, I would force users to use that <code>"base_directory" =&gt; "/vagrant"</code> key/value pair in their <code>Vagrantfile</code>.</p> <p><strong>Is there an API method to get this synched directory path on VM in the recipe code?</strong> Or more genarally: is there a way to get Vagrant-specific properties from Chef recipes?</p> <p>I scoured Vagrant docs, but there seems to be just a <a href="http://docs.vagrantup.com/v2/synced-folders/basic_usage.html" rel="nofollow">single page on that topic</a>, and because it is specific to Vagrant, there is no related information in <a href="http://docs.opscode.com/" rel="nofollow">Chef docs</a> either.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload