"NameError: undefined local variable or method 'config' for main:Object" when trying to set Vagrant proxy - vagrant

I'm very new to Vagrant (just installed it yesterday). And I am trying to set my proxy settings as per this answer. I have already installed the proxyconf plugin.
I am running Windows 7 64-bit. I assumed that the Vagrantfile in question was C:\Users\<my username>\.vagrant.d\Vagrantfile. This file did not exist, so I created it with the contents set to just the three lines given in the answer linked above (with yourproxy replaced by my actual proxy of course):
config.proxy.http = "http://yourproxy:8080"
config.proxy.https = "http://yourproxy:8080"
config.proxy.no_proxy = "localhost,127.0.0.1"
Now I am trying to run a Vagrant command (which I got from another online tutorial)
vagrant box add bento/centos-7 --provider=virtualbox
When I run it, I get the following:
There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.
Path: C:/Users/<my username>/.vagrant.d/Vagrantfile
Line number: 0
Message: NameError: undefined local variable or method `config' for main:Object
Sorry as this is probably down to my extremely limited knowledge of Vagrant, but can someone help me as to how to set it up correctly?

Need to put Vagrant.configure("2") do |config| before these lines and end after them. This is missed from the answer which I was quoting from.

Related

config-custom.yaml not loading on vagrant / puppet VM

I'm trying to use a custom config file in my vagrant machine.
I have all the main params in the puphpet\config.yaml
and the local overrides in puppet\config-custom.yaml
I couldn't get the file to load so after much searching i figured i needed to change the vagrant file
so i added
configValues = YAML.load_file("#{dir}/puphpet/config.yaml")
if File.file?("#{dir}/puphpet/config-custom.yaml")
custom = YAML.load_file("#{dir}/puphpet/config-custom.yaml")
configValues.deep_merge(custom)
end
data = configValues['vagrantfile-local']
but this just gives me
Message: NoMethodError: undefined method `deep_merge' for #<Hash:0x00000101b6bac8>
originally the code said
configValues.deep_merge!(custom)
But that did not work either,

Vagrant Windows-1251 encoding error

I got the next error with vagrant when trying to use "vagrant up" command:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'precise32'...
C:/HashiCorp/Vagrant/embedded/gems/gems/childprocess-0.5.3/lib/childprocess/wind
ows/process_builder.rb:43:in `join': incompatible character encodings: Windows-1
251 and UTF-8 (Encoding::CompatibilityError)
I have Windows 8.1, and I used "chcp 1251" command before, because it was the same error with "ibm866" encoding.
Thanks!
Problem was solved by setting environment variable VAGRANT_HOME
the solution for me was this one .
You have to go to : c:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.3\bin\vagrant
And edit the vagrant (file) and put after this : #!/usr/bin/env ruby
this 2 lines
Encoding.default_external = Encoding.find('Windows-1250')
Encoding.default_internal = Encoding.find('Windows-1250')
Good luck!
Set an environtment variable VAGRANT_HOME to the path, for example 'c:\HashiCorp'
Then add to c:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.3\bin\vagrant after #!/usr/bin/env ruby these two lines:
Encoding.default_external = Encoding.find('Windows-1251')
Encoding.default_internal = Encoding.find('Windows-1251')
Notice Windows-1251, not Windows-1250.
And I think you might need to reboot to enable the environment variable.
Yes, setting environment variable VAGRANT_HOME can solve the problem.
I think it's mainly because vagrant up command would try to visit %userprofile%\.vagrant.d folder, however, your %userprofile% is named in Windows 1251 encoding. Setting VAGRANT_HOME can point to a path recognizable for vagrant's ruby script.
If you stil having some trouble with it, even after seting env variable, try just to move your "homestead" folder to a path that not contains any cyrilic symbols.
Or you can create another user in you system without cyrilc
Hope it helps!

vagrant: how to add GUI to vagrant by modifying Vagrantfile?

I need to see the GUI when I do "vagrant up --provision" because I believe the box was shutdown improperly and now simply time-outs when I try to start it. I see from the [documentation] that I can add a block to my Vagrantfile to enable me to debug the startup process. This post says if the system was shutdown improperly it will ask me if I want to boot up in safe mode (only visible from the GUI). So I am trying to modify the Vagrantfile and have tried two ways (I'm not very familiar with Ruby or modifying config files). When I try this:
VAGRANTFILE_API_VERSION = "2"
path = "#{File.dirname(__FILE__)}"
require 'yaml'
require path + '/scripts/homestead.rb'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
Homestead.configure(config, YAML::load(File.read(path + '/Homestead.yaml')))
config.vm.provider "virtualbox" do |v|
vb.gui = true
end
end
I get the following error message:
Path: <provider config: virtualbox>
Message: undefined local variable or method `vb' for main:Object
Could anyone please tell me what I am doing wrong? How do I modify the file properly so that I can get the vagrant box up and running again. I am trying to use Homestead for Laravel, by the way. Thank you very much!

Vagrant not able to find home/vagrant/hiera.yaml

I have inherited a python app that uses Puppet, Vagrant and VirtualBox to provision a local Centos test machine.
This app was written on Mac and I'm developing on Windows.
When I run vagrant up I see a large list of command line errors, the most relevant of which is:
Running Puppet with site.pp..
Warning: Config file /home/vagrant/hiera.yaml not found, using Hiera defaults
WARN: Fri Apr 25 16:32:24 +0100 2014: Not using Hiera::Puppet_logger. It does not report itself to b
e suitable.
I know what Hiera is, and why it's important, but I'm not sure how to fix this.
The file hiera.yaml is present in the repo but it's not found at home/vagrant/hiera.yaml, instead it's found at ./puppet/manifests/hiera.yaml.... Similarly if I ssh into the box, there is absolutely nothing whatsoever inside home/vagrant but I can find this file when I look in /tmp
So I'm confused, is vagrant looking inside the Virtual box and expecting this file to be found at home/vagrant/hiera.yaml? Or have I inherited an app that did not work properly in the first place? I'm really stuck here and I can't get in touch with the original dev.
Here are some details from my Vagrantfile:
Vagrant.configure("2") do |config|
# Base box configuration ommitted
# Forwarded ports ommitted
# Statically set hostname and internal network to match puppet env ommitted
# Enable provisioning with Puppet standalone
config.vm.provision :puppet do |puppet|
# Tell Puppet where to find the hiera config
puppet.options = "--hiera_config hiera.yaml --manifestdir /tmp/vagrant-puppet/manifests"
# Boilerplate Vagrant/Puppet configuration
puppet.module_path = "puppet/modules"
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "site.pp"
# Custom facts provided to Puppet
puppet.facter = {
# Tells Puppet that we're running in Vagrant
"is_vagrant" => true,
}
end
# Make the client accessible
config.vm.synced_folder "marflar_client/", "/opt/marflar_client"
end
It's really strange.
There's this puppet.options line that tells Puppet where to look for hiera.yaml and currently it simply specifies the file name. Now, when you run vagrant up, it mounts the current directory (the one that has the Vagrantfile in it) into /vagrant on the guest machine. Since you're saying hiera.yaml is actually found in ./puppet/manifests/hiera.yaml, I believe you want to change the puppet.options line as follows:
puppet.options = "--hiera_config /vagrant/puppet/manifests/hiera.yaml --manifestdir /tmp/vagrant-puppet/manifests"
To solve this warning, you may first try to check from where this file is referenced, i.e.:
$ grep -Rn hiera.yaml /etc/puppet
/etc/puppet/modules/stdlib/spec/spec_helper_acceptance.rb:13: on hosts, '/bin/touch /etc/puppet/hiera.yaml'
/etc/puppet/modules/mysql/spec/spec_helper_acceptance.rb:34: shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
In this case it's your vagrant file.
You may also try to find the right path to it via:
sudo updatedb && locate hiera.yaml
And either follow the #EvgenyChernyavskiy suggestion, create a symbolic link if you found the file:
sudo ln -vs /etc/hiera.yaml /etc/puppet/hiera.yaml
or create the empty file (touch /etc/puppet/hiera.yaml).
In your case you should use the absolute path to your hiera.yaml file, instead of relative.
The warning should be gone.

Unable to use application_ruby cookbook with Chef 11.8.0, Cannot find a resource for bundle_options

I have been attempting to setup a chef recipe which installs ruby using RVM and then uses the application_ruby cookbook to configure the application, however I keep running into the error
NameError: Cannot find a resource for bundle_options on ubuntu version 12.04
I am using the following code
application "application setup" do
owner "ubuntu"
group "ubuntu"
repository "https://github.com/me/myapplication.git" // Real address removed
path rails_app_path
revision "master"
rails do
bundler true
precompile_assets true
bundler_deployment true
end
end
I noticed that the bundle_options was recently added, https://github.com/opscode-cookbooks/application_ruby/commit/e7719170a661a957796e8e5d58ba8f4ecd937487 however I am unable to track down if this is causing the issue. I have included
depends "application"
depends "application_ruby"
in my metadata.rb and made sure all my dependencies are installed so I am unsure what I am doing wrong at this point.
According to documentation bundle_options is an attribute of the rails resource, not a resource itself.
The only correct way of using it is INSIDE the "rails" block, so you got the message because you either used it as :
an attribute of the application resource (but outside of the "rails" block)
standalone resource (outside of any resource).
Message you mentioned is being displayed when nonexistent resource is being referenced. e.g. if you had tried to execute following code on your system:
nonexistent_resource "failure gonna happen" do
some_attribute "whatever_value"
end
you would've got a message
NameError: Cannot find a resource for nonexistent_resource on Ubuntu version 12.04
I ran into this problem today as well. It appears the problem is that commit e771917 forgot to add the necessary getter for the bundle_option. Someone filed a PR to fix it (https://github.com/poise/application_ruby/pull/44), but it has not yet been merged. I can confirm that when I made that change locally, this error went away. The forked branch in the PR is located at https://github.com/mauriciosilva/application_ruby/tree/bundle_options_fix.

Resources