Mcollective Chef service agent failed to run - ruby

I have configure mcollective and install following service agent to start/stop service
https://github.com/rottenbytes/mcollective/blob/master/plugins/agents/chef-service.rb
But when i running it, its failing at client.build_node and i am seeing error undefined method reset_defaults_and_overrides for nil:NilClass (NoMethodError)
require 'chef'
require 'chef/client'
require 'chef/run_context'
begin
Chef::Config[:solo] = true
Chef::Config[:log_level] = :debug
Chef::Log.level(:debug)
client = Chef::Client.new
client.run_ohai
client.build_node <-- its failing here
If i try to run on my shell i get following
[root#node1 agent]# ruby /tmp/foo.rb
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/policy_builder/expand_node_object.rb:117:in `build_node': undefined method `reset_defaults_and_overrides' for nil:NilClass (NoMethodError)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:259:in `build_node'
from /tmp/foo.rb:11:in `<main>'
I am not ruby expert so i don't know how to fix it. I just need clue what is going on

From the looks of it, enough of the internal API for chef client has changed that the mcollective plugin won't work anymore. Try an older version of the chef gem.

Related

Ruby NoMethodError exception calls #inspect by default

I have found a weird problem in Ruby and I'm not quite sure if it is an issue or it's a feature introduced in recent Ruby versions.
Basically when we call an undefined method, we get an undefined method error as expected in Ruby. The issue is that it also calls inspect and prints out the object and all of its attributes/values. If my object is a complex one, it takes really long time to finish printing everything out and in many times it causes my local rails server to hang, especially when there is an attribute holding binary data. This issue does not seem to happen with Ruby 2.6 but Ruby >= 2.7.
For simple objects, that's not a problem but I'm specifically having the issue with this gem: puppeteer-ruby. Each object in this gem has lots of attributes and dependencies.
Here is an example, I run the following code in IRB with different Ruby version and getting different exceptions:
require 'puppeteer-ruby'
browser = Puppeteer.launch(headless: true)
browser.foo
Ruby 2.6.6
NoMethodError: undefined method `foo' for #<Puppeteer::Browser:0x00007fce2d553b30>
Did you mean? for
Ruby 3.0.0
(irb):9:in `<main>': undefined method `foo' for #<Puppeteer::Browser:0x00007f9300550740 #ignore_https_errors=false, #default_viewport=#<Puppeteer::Viewport:0x00007f92ffbf8e90 #width=800, #height=600, #device_scale_factor=1.0, #is_mobile=false, #has_touch=false, #is_landscape=false>, #process=#<Puppeteer::BrowserRunner::BrowserProcess:0x00007f92fc5ae448 #spawnargs=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=Translate", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-popup-blocking", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--disable-sync", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--enable-blink-features=IdleDetection", "--headless", "--hide-scrollbars", "--mute-audio", "about:blank", "--remote-debugging-port=0", "--user-data-dir=/var/folders/qn/kx4kb8xx5x13gx77yy2q56fr0000gn/T/puppeteer_dev_chrome_profile-20210910-25051-m7mnxb"], #stdout=#<IO:fd 24>, #stderr=#<IO:fd 26>,......very long text after this..
Thats interesting - inspect has always printed internal variables.
In the blame the last change to inspect was 9 years ago: rb_object_inspect#704
A simple script using 2.6:
> docker run -it ruby:2.6.6-alpine sh
#> ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux-musl]
#> irb
irb(main):001:0> class Foo; def initialize(message); #message = message; end; end
=> :initialize
irb(main):002:0> Foo.new('hello').foo
NoMethodError (undefined method `foo' for #<Foo:0x00007f35e20e0280 #message="hello">)
Did you mean? for
Though looking at the source for Puppeteer::Browser it seems they changed to a pure ruby implementation of the browser around 2 years ago. When they did that they introduced a lot of ivars to the class. Perhaps the version you're using changed between updating ruby from 2.6 to 3.0?
A simple fix would be to monkey patch inspect on Puppeteer::Browser, or send a PR to the maintainer - looks like the project is active on GitHub.

Using ruby and aws-sdk to pull ec2 tags

Folks,
I am trying to pull in the EC2 tags via ruby aws-sdk and iam roles. The following bit of code produces error below. What am I doing wrong?
require 'rubygems'
require 'aws-sdk'
require 'fileutils'
ec2 = AWS::EC2.new()
instance_id = `wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
outdir = '/opt/facts/tags/'
unless File.directory?(outdir)
FileUtils.mkdir_p(outdir)
end
ec2= AWS::EC2.new()
instance = ec2.instances[instance_id]
tags = instance.tags
tags.each do |num|
File.open(outdir+num[0], "w") do |f|
f.write(num[1])
end
end
Following output:
/usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/http/connection_pool.rb:127:in `session_for': undefined method `continue_timeout=' for #<Net::HTTP ec2.us-east-1.amazonaws.com:443 open=false> (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/http/net_http_handler.rb:52:in `handle'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:236:in `make_sync_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:262:in `retry_server_errors'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:229:in `make_sync_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:489:in `client_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:371:in `log_client_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:457:in `client_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:353:in `return_or_raise'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:456:in `client_request'
from (eval):3:in `describe_tags'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/ec2/filtered_collection.rb:44:in `send'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/ec2/filtered_collection.rb:44:in `filtered_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/ec2/resource_tag_collection.rb:156:in `each'
from ./puppetclient.rb:22
That seems to be a bug that was already reported today: undefined method `continue_timeout=', you could try pointing to the main branch of the git repository since there's already a patch for it.
Edit:
You can already point the latest version in rubygems since they already deployed the fix on version 1.9.1:
https://rubygems.org/gems/aws-sdk
There was a bug announced today in AWS-SDK-ruby https://github.com/aws/aws-sdk-ruby/issues/232
You can fix it by updating your gemfile
gem 'aws-sdk', "1.9.1"
And then running "bundle"

Sinatra heroku database access

I have a sinatra ruby app in heroku. I am trying to access the database via the console.When I run the heroku run console , I am getting the following error.
Running console attached to terminal... up, run.10
/app/vendor/ruby-1.9.2/lib/ruby/1.9.1/irb/init.rb:281:in `require':LoadError: no such file to load -- ./console.
When I try to access the record using the following command, I am getting the following error :
irb(main):001:0> Setting.first
NameError: uninitialized constant Object::Setting
from (irb):1
from bin/irb:12:in `<main>'
Can anyone help me in what needs to be done. Am I missing some file or Is there a different way to access the tables in heroku?
The heroku console thing is an old hack for rails apps, but it won't work elsewhere. As you can see from the output, it's trying to load a file called ./console. So, create a console file on your project root, and invoke IRB from it after having connected to your database. For example:
#!/usr/bin/env ruby
require 'irb'
require 'irb/completion'
require 'rubygems'
require 'bundler/setup'
# require something that connects to your database
# or just connect here using ENV['DATABASE_URL']
require 'your_project_setup'
IRB.start

What is ths error in Ruby Watir (WIN32OLERuntimeError: unknown property or method `document')?

I have this code in Ruby waitr ..
$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'..') if $0 == __FILE__
require 'test/unit'
require 'Watir'
require 'Watir/contrib/enabled_popup'
class TC_Dialog_Test<Test::Unit::TestCase
$ie=Watir::IE.new
$ie.bring_to_front()
$myDir = File.expand_path(File.dirname(__FILE__))
def setup
$ie.goto "file://#{$myDir}/aa.html"
end
def test_confirm_OK
sleep(3)
$ie.button(:id, 'btnConfirm').click_no_wait
$hwnd = $ie.enable_popup(5)
if ($hwnd)
$popup =WinClicker.new
$popup.makeWindowsActive($hwnd)
sleep(3)
# $popup.clickWindowsButton($hwnd,"OK")
puts "you pressed Comfirm-ok"
sleep(3)
end
end
end
when runnung this code get this error results ...
test_confirm_OK(TC_Dialog_Test):
WIN32OLERuntimeError: unknown property or method `document'
HRESULT error code:0x800706b5
The interface is unknown.
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/ie.rb:417:in `method_missing'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/ie.rb:417:in `document'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/container.rb:767:in `ole_inner_elements'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/container.rb:838:in `locate_input_element'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/input_elements.rb:10:in `locate'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:47:in `assert_exists'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:278:in `enabled?'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:53:in `assert_enabled'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:214:in `click_no_wait'
Mo.rb:16:in `test_confirm_OK'
You are using Watir 1.5.3, but the current stable is 1.8.1. I suggest you to update your gem to the latest and try again. There is a good chance that the WIN32OLE object for IE has changed it's behavior and old gem is conflicting with it. (Have you updated IE or smth since last successful run?)
I got the same error using Watir 1.8.1. I don't know if there is anything wrong with your code, but in my case the tests ran fine on other machines.
I am running my tests in RubyMine 3.1.x. Running RubyMine as Administrator allowed Ruby to have the rights to interact with IE properly and the problem went away.
Edit:
Found the forum post which originally helped me solve the problem.

ruby-openid: #socket not set while performing discovery

I'm having a bit of truble with omniauth/openid.
When trying to authenticate, I found this in my logs:
OpenID::FetchingError: Error fetching https://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username: undefined method `io' for nil:NilClass
The important thing there is undefined method io' for nil:NilClass which comes from openid/fetchers.rb, in the following snippet:
module Net
class HTTP
def post_connection_check(hostname)
check_common_name = true
cert = #socket.io.peer_cert
cert.extensions.each { |ext|
next if ext.oid != "subjectAltName"
ext.value.split(/,\s+/).each{ |general_name|
if /\ADNS:(.*)/ =~ general_name
check_common_name = false
...
That error is generated by #socket.io.peer_cert, #socket is not defined.
Have any of you encountered this before? Not quite sure what the cause is.
Versions I'm running:
ruby 1.9.3dev (2010-08-17 trunk 29020) [x86_64-darwin10.4.0]
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
omniauth 0.2.0
We had this same problem and it was a direct result of Net::HTTP#connect never being invoked. Turns out we had the fakeweb gem scoped into the environment that was throwing the error (development, in our case).
Narrowing fakeweb's scope allows for normal processing of #connect and #socket is once again happy.
group :test do
gem 'fakeweb'
end
We came across the same / very similar problem with both fakeweb and webmock (when using the VCR gem). Switching from fakeweb to typhoeus seemed to have solved this problem for us.

Resources