What you can use is something like this:

  puts File.join(File.expand_path(File.dirname(__FILE__)), "Vagrantfile")

  puts File.dirname(__FILE__)



On Sun, Apr 26, 2015 at 6:06 AM, Dalibor Karlović <[email protected]> wrote:
> Hello Alvaro, thank you very much for your answer.
>
> I'll start by linking the GH repo where you can see what I'm trying to do:
> https://github.com/dkarlovi/vagrant-playground
>
> Now, to me more concrete:
>
> my custom box is called dkarlovi/centos-6.6
> it gets embedded with a custom Vagrantfile,
> https://github.com/dkarlovi/vagrant-playground/blob/master/box/_Vagrantfile
> when installed, that Vagrantfile ends up in
> /home/dkarlovi/.vagrant.d/boxes/dkarlovi-VAGRANTSLASH-centos-6.6/1.0.0/virtualbox/include/_Vagrantfile
> I create a new Vagrant project in /home/dkarlovi/Vagrant/project1, vagrant
> init dkarlovi/centos-6.6 --minimal
> when running, I can see that the /home/dkarlovi/Vagrant/project1/Vagrantfile
> gets evaluated before
> /home/dkarlovi/.vagrant.d/boxes/dkarlovi-VAGRANTSLASH-centos-6.6/1.0.0/virtualbox/include/_Vagrantfile
> so I should, in theory, be able to figure out where's the Vagrantfile that
> started it all
> I'm currently simulating this, see line 11 but this does not work if I run
> vagrant from say /home/dkarlovi/Vagrant/project1/src
>
> I'm doing all of this to be able to check for existence of certain files
> (Puppet related) and turn provisioning on/off so I'd be able to have a full
> Puppet stack (if files present) or nothing (if not present), my box becomes
> more versatile and usable (for my usages).
>
> I've been going through Vagrant source and found that
> Vagrant::Config::Loader is the place where the path is available, but I
> don't see where and how I should fetch it.
>
>
> Dana subota, 25. travnja 2015. u 19:15:00 UTC+2, korisnik Alvaro Miranda
> Aguilera napisao je:
>>
>> Hello Dalibor,
>>
>> Are 2 things to take into consideration.
>>
>> This is the overall simple answer, so apologies in advance if all this
>> is known and doesn't answer your question.
>>
>> One is, Vagrant will load all the Vagrantfiles and follow this rule:
>>
>> https://docs.vagrantup.com/v2/vagrantfile/index.html
>>
>> <QUOTE>
>> Vagrant actually loads a series of Vagrantfiles, merging the settings
>> as it goes. This allows Vagrantfiles of varying level of specificity
>> to override prior settings. Vagrantfiles are loaded in the order shown
>> below. Note that if a Vagrantfile is not found at any step, Vagrant
>> continues with the next step.
>>
>> Vagrantfile packaged with the box that is to be used for a given machine.
>> Vagrantfile in your Vagrant home directory (defaults to ~/.vagrant.d).
>> This lets you specify some defaults for your system user.
>> Vagrantfile from the project directory. This is the Vagrantfile that
>> you'll be modifying most of the time.
>> Multi-machine overrides if any.
>> Provider-specific overrides, if any.
>>
>> At each level, settings set will be merged with previous values. What
>> this exactly means depends on the setting. For most settings, this
>> means that the newer setting overrides the older one.
>>
>> </QUOTE>
>>
>> So by default it should read and merge all the Vagrantfiles.
>>
>> If your base box include other files, you can reference them like this:
>>
>> include_vagrantfile = File.expand_path("../include/_Vagrantfile",
>> __FILE__)
>> load include_vagrantfile if File.exist?(include_vagrantfile)
>> config.ssh.private_key_path = File.expand_path("../vagrant_rsa", __FILE__)
>>
>> This came from this thread as example:
>> http://comments.gmane.org/gmane.comp.tools.vagrant/4813
>>
>> Alvaro.
>>
>> On Sun, Apr 26, 2015 at 3:48 AM, Dalibor Karlović <[email protected]>
>> wrote:
>> > Hello,
>> >
>> > I have a custom box which contains a embedded Vagrantfile (let's call it
>> > VF1). This file contains a lot of box-specific config / functionality
>> > and
>> > the target is I should be (and am) able to generate the project
>> > Vagrantfile
>> > (VF2) just with:
>> >
>> > Vagrant.configure(2) do |config|
>> >   config.vm.box = "my/box"
>> > end
>> >
>> > and still get all the functionality (Puppet integration, VirtualBox
>> > tweaks,
>> > YAML config support, etc). The problem is that I'd like to read files
>> > relative to VF2 from VF1. The way I see it, VF2 gets loaded before VF1
>> > and
>> > thus, Vagrant should be able to figure out where VF2 is before loading
>> > loading VF1. So, how do I access this information?
>> >
>> > Thanks in advance.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Vagrant" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to [email protected].
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to