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

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,

Related

Ruby returns uninitialized constant error when trying to include a module within a chef recipe

I have a java/recipes/windows recipe that uses a method called win_friendly_path and it doesn't work because win_friendly_path is not yet defined.
win_friendly_path is however defined in the ../windows/libraries/windows_helper.rb as follows:
module Windows
module Helper
def win_friendly_path(path)
path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR || '\\') if path
end
I already have my berksfile and metadata.rb setup in the java (./) recipe to depend on the windows cookbook.
I'm not sure how to include this module so right now I am trying to just use include WindowsHelper in the java/cookbook/windows recipe and receiving this error:
uninitialized constant #<Class:#<Chef::Recipe:0x00000000029a2188>>::WindowsHelper
I have tried several variations of this and now feel like I have spent way too much time troubleshooting the issue so any help is appreciated.
UPDATE: plugging in this line ::Chef::Resource.send(:include, Windows::Helper) to my java/recipes/windows recipe gives me the following error:
Chef::Exceptions::ValidationFailed
----------------------------------
value is a required property
Try this
include Windows::Helper
Inserting the following line resolved this issue for me:
::Chef::Recipe.send(:include, Windows::Helper)
This allows me to use the variables following module from the windows cookbook:
module Windows
module Helper
...
{Variable}
{Other_variable}
...

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

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.

org.jruby.exceptions.RaiseException: (NameError) uninitialized constant

I'm getting the following error from a JRuby wrapping of the ActiveMerchant library:
org.jruby.exceptions.RaiseException: (NameError) uninitialized constant ActiveMerchant::Billing::SecurePayAuGateway
at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java:3345)
at org.jruby.RubyModule.const_get(org/jruby/RubyModule.java:3290)
at RUBY.createGateway(classpath:/scripts/main.rb:79)
The code initiating it is:
gateway = ActiveMerchant::Billing::const_get(name).new(options)
I think this is happening because there is some dynamic loading of the gateways happening in gateways.rb:
module ActiveMerchant
module Billing
load_path = Pathname.new(__FILE__ + '/../../..')
Dir[File.dirname(__FILE__) + '/gateways/**/*.rb'].each do |filename|
gateway_name = File.basename(filename, '.rb')
gateway_classname = "#{gateway_name}_gateway".camelize
gateway_filename = Pathname.new(filename).relative_path_from(load_path).sub_ext('')
autoload(gateway_classname, gateway_filename)
end
end
end
This works during unit tests because the Ruby files are real files in my target directory. However in the final application, the Ruby files are contained within a Jar which is in a Jar.
Anyone know why this is happening and how to get it to work?
Which gateway are you trying to teach? From Active Merchant's github there is no
ActiveMerchant::Billing::SecurePayAuGateway
But there is a
ActiveMerchant::Billing::SecurePayGateway
And a
ActiveMerchant::Billing::SecurePayTechGateway
To test, instead of
gateway = ActiveMerchant::Billing::const_get(name).new(options)
Try
gateway = ActiveMerchant::Billing::SecurePayGateway
If this works, you know the problem is your gateway = method and you can fix this accordingly

Add a custom function in puppet

I'm trying to port a Ruby script in puppet. As far as I know, the only way to achieve that is by creating a custom function in a module. Feel free to tell me if there's another way. I tried my first test as shown on https://docs.puppetlabs.com/guides/custom_functions.html , I declared a new module in:
/etc/puppet/modules/custom_module
and edited a new function file called /etc/puppet/modules/custom_module/lib/puppet/parser/functions/newfunction with this code:
module Puppet::Parser::Functions
newfunction(:write_line_to_file) do |args|
filename = args[0]
str = args[1]
File.open(filename, 'a') {|fd| fd.puts str }
end
end
Then I used in this manifest /etc/puppet/environments/desarrollo/manifests/des.pp with this content:
node "develserver" {
write_line_to_file('/tmp/some_file', "Hello world!")
}
And finally when I run a puppet agent -tod it shows me the following error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Unknown function write_line_to_file at /etc/puppet/environments/desarrollo/manifests/des.pp:5 on node develserver
What am I doing wrong?
The immediate problem is likely the missing .rb extension on your function file name.
Keep in mind that the Ruby code is run on the master during catalog compilation. If you want Puppet to take action on the agent side, you cannot use custom functions. You will have to write a custom Resource Type (and often a Provider) to do that.

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!

Resources