maoueh/nugrant

How to use .vagrantuser with multi-machine functionality

Closed this issue · 5 comments

How could i set in the .vagrantuser file, the parameters for a specific vm on a multi-machine environment?

I guess I would go with a specific parameters for each machine, something like this.

# File .vagrantuser
servers:
  '1': 
    ip: 10.0.0.132
    location: /var/lib

  '2':
    ip: 10.0.0.133
    location: /var/lib

balancer:
  ip: 10.0.0.133
# File Vagrantfile
  config.user.servers.each do |id, server_config|
    config.vm.define "server_#{id}" do |server|
      server.vm.network :private_network, ip: server_config.ip
    end
  end

  servers = config.user.servers.map { |id, info| id.to_s }

  config.vm.define "balancer" do |balancer|
    balancer.vm.network :private_network, ip: config.user.balancer.ip

    balancer.vm.provision :chef_solo do |chef|
      # Chef configuration skipped

      chef.json = {
        'servers' => servers.join(", ") 
      }
    end
  end

Regards,
Matt

I understand, but that way, the parameters are listed like this:

vagrant user parameters
/home/pablocrivella/.vagrant.d/gems/gems/nugrant-2.1.0/lib/nugrant/vagrant/v2/command/env.rb:5: warning: already initialized constant EnvExporter
/home/pablocrivella/.vagrant.d/gems/gems/nugrant-2.1.0/lib/nugrant/vagrant/v2/action/auto_export.rb:5: warning: previous definition of EnvExporter was here
# Vm 'php'
 All Parameters
 --------------------------------------------------
 config:
   user:
     php:
       folders: []
       ports: []
       networks:
         private:
         - ip_address: 192.168.100.10
       cpus: 1
       memory: 1024
     ruby:
       folders: []
       ports: []
       networks:
         private:
         - ip_address: 192.168.100.20
       cpus: 1
       memory: 1024


# Vm 'ruby'
 All Parameters
 --------------------------------------------------
 config:
   user:
     php:
       folders: []
       ports: []
       networks:
         private:
         - ip_address: 192.168.100.10
       cpus: 1
       memory: 1024
     ruby:
       folders: []
       ports: []
       networks:
         private:
         - ip_address: 192.168.100.20
       cpus: 1
       memory: 1024

They are repeated for every vm, i thought maybe there was a way to specify params for a specific vm like when you do this:

config.vm.define "balancer" do |balancer|
  balancer.user.defaults = {
      some_value: 'some value'
  }
end

Here the explanation.

The levels are <defaults>, <project>, <user>, <system>. Each vm has its own config.user object where <defaults> is defined. The rest are shared by at least one Vagrantfile. Hence, <project> level (i.e. .vagrantuser) is shared for each vm in a single file.

The display is liked that because <defaults> could be different by vm, but it is not scoped to it, meaning the defaults in balancer, you still need:

config.user.defaults = {
  'balancer' => {
    'ip' => "other ip"  
  }
}

To override a value correctly. I know the display make it appears like it could be possible, but it could not.

Maybe the vagrant user parameters should be displayed differently. At least, I will add a note about this in the README.md. Also, maybe I could add a scope configuration option to scope parameters to a dedicated level. Not sure it worth it however.

Thanks for the explanation! Maybe it does not worth the effort.

Indeed :) I will close this then.