Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `gsub' for nil:NilClass following net-ssh patch upgrade #263

Closed
esciara opened this issue Jan 13, 2015 · 13 comments
Assignees
Milestone

Comments

@esciara
Copy link

esciara commented Jan 13, 2015

As discussed on gitter, a problem appeared following the patch 2.9.2 of the net-ssh gem. Symptoms are that the error below show when converging a chef-provisioning recipe (output in debug mode):

                      ================================================================================
                      Chef encountered an error attempting to load the node data for "simplest-server"
                      ================================================================================

                      Unexpected Error:
                      -----------------
                      NoMethodError: undefined method `gsub' for nil:NilClass

                      [2015-01-13T15:46:19+00:00] DEBUG: Re-raising exception: NoMethodError - undefined method `gsub' for nil:NilClass
                      /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/mixlib-authentication-1.3.0/lib/mixlib/authentication/signedheaderauth.rb:120:in `canonical_path'
                        /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/mixlib-authentication-1.3.0/lib/mixlib/authentication/signedheaderauth.rb:145:in `canonicalize_request'
                        /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/mixlib-authentication-1.3.0/lib/mixlib/authentication/signedheaderauth.rb:93:in `sign'
                        /opt/chef/embedded/apps/chef/lib/chef/http/auth_credentials.rb:51:in `signature_headers'
                        /opt/chef/embedded/apps/chef/lib/chef/http/authenticator.rb:88:in `authentication_headers'
                        /opt/chef/embedded/apps/chef/lib/chef/http/authenticator.rb:43:in `handle_request'
                        /opt/chef/embedded/apps/chef/lib/chef/http.rb:222:in `block in apply_request_middleware'
                        /opt/chef/embedded/apps/chef/lib/chef/http.rb:220:in `each'
                        /opt/chef/embedded/apps/chef/lib/chef/http.rb:220:in `inject'
                        /opt/chef/embedded/apps/chef/lib/chef/http.rb:220:in `apply_request_middleware'
                        /opt/chef/embedded/apps/chef/lib/chef/http.rb:141:in `request'
                        /opt/chef/embedded/apps/chef/lib/chef/rest.rb:115:in `get'
                        /opt/chef/embedded/apps/chef/lib/chef/node.rb:496:in `load'
                        /opt/chef/embedded/apps/chef/lib/chef/node.rb:480:in `find_or_create'
                        /opt/chef/embedded/apps/chef/lib/chef/policy_builder/expand_node_object.rb:92:in `load_node'
                        /opt/chef/embedded/apps/chef/lib/chef/client.rb:219:in `load_node'
                        /opt/chef/embedded/apps/chef/lib/chef/client.rb:386:in `run'
                        /opt/chef/embedded/apps/chef/lib/chef/application.rb:261:in `block in fork_chef_client'
                        /opt/chef/embedded/apps/chef/lib/chef/application.rb:249:in `fork'
                        /opt/chef/embedded/apps/chef/lib/chef/application.rb:249:in `fork_chef_client'
                        /opt/chef/embedded/apps/chef/lib/chef/application.rb:215:in `block in run_chef_client'
                        /opt/chef/embedded/apps/chef/lib/chef/local_mode.rb:38:in `with_server_connectivity'
                        /opt/chef/embedded/apps/chef/lib/chef/application.rb:201:in `run_chef_client'
                        /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:355:in `block in interval_run_chef_client'
                        /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:345:in `loop'
                        /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:345:in `interval_run_chef_client'
                        /opt/chef/embedded/apps/chef/lib/chef/application/client.rb:335:in `run_application'
                        /opt/chef/embedded/apps/chef/lib/chef/application.rb:58:in `run'
                        /opt/chef/embedded/apps/chef/bin/chef-client:26:in `<top (required)>'
                        /usr/bin/chef-client:40:in `load'
                        /usr/bin/chef-client:40:in `<main>'

The problem is resolved by locking the net-ssh version to 2.9.1. An example simple Gemfile on a recipe using the fog driver is:

source 'https://rubygems.org'

gem 'chef-dk'
gem 'chef-provisioning'
gem 'chef-provisioning-fog'
gem 'net-ssh', '= 2.9.1

Two issues here:

  1. The NoMethodError: undefined method 'gsub' for nil:NilClass is somewhat cryptic and has made it difficult to find the origin of the problem (see discussion here: https://gitter.im/opscode/chef-provisioning/archives/2014/12/31; or ticket here: confusing exception thrown when chef_server_url is not a full URI )
  2. Can this problem be solved at CP's level? Or chef-dk's?
@esciara
Copy link
Author

esciara commented Jan 13, 2015

Just to be more precise on the versions involved here in the Gemfile:

source 'https://rubygems.org'

gem 'chef-dk', '0.3.5'
gem 'chef-provisioning', '0.17'
gem 'chef-provisioning-fog', '0.11'
gem 'net-ssh', '= 2.9.1'

@mfazekas
Copy link

@esciara is there an easy way i can reproduce this?
Can you also try with 2.9.2.beta and 2.9.2.rc1 rc2 and rc3?

net-ssh/net-ssh@v2.9.1...v2.9.2
Shows alll changes between 2.9.1 and 2.9.2.

@Afterglow
Copy link

@mfazekas if you create the most basic recipe possible with 1 machine in vagrant and uses net-ssh 2.9.2 it will fail, at least it does for me

@esciara
Copy link
Author

esciara commented Jan 13, 2015

@mfazekas yes. Do as follow (from memory but I am pretty sure it will work, with little addition):

  1. Clone https://github.com/esciara/chef-provisioning-examples

  2. Add a Gemfile with the following in it: (you could actually lock the versions of these gems following the example in my previous comment)

    source 'https://rubygems.org'
    
    gem 'chef-dk'
    gem 'chef-provisioning'
    gem 'chef-provisioning-fog'
  3. Run a bundle install

  4. Follow the README.md file to make sure you set up your AWS credentials correctly.

  5. Change the :key_name => 'chefserver' to your own key in the aws_setup.rb file

  6. Run the simplest example with bundle exec chef-client -z aws_setup.rb simplest_machine.rb (and to obtain debug log, add -l debug at the end)

@esciara
Copy link
Author

esciara commented Jan 13, 2015

@mfazekas having said that, (following on @Afterglow 's comment) if you don't have credentials for AWS, you could also use the vagrant set up as follows:

  1. Clone https://github.com/esciara/chef-provisioning-examples

  2. Add a Gemfile with the following in it: (you could actually lock the versions of these gems following the example in my previous comment)

    source 'https://rubygems.org'
    
    gem 'chef-dk'
    gem 'chef-provisioning'
    gem 'chef-provisioning-vagrant'
  3. Run a bundle install

  4. Follow the README.md file to make sure you followed the requirements for vagrant.

  5. Run the simplest example with bundle exec chef-client -z vagrant_setup.rb simplest_machine.rb (and to obtain debug log, add -l debug at the end)

I reproduced the problem following these exact steps just now.

@mfazekas
Copy link

I was able to reproduce the issue - strage :chef_server_url=>"http::8889"in Chef::Config not sure how it's related to net-ssh.

@mfazekas
Copy link

Looks like this commit - from opscode - is to blame:
net-ssh/net-ssh@8af2863

@jkeiser can you please take a look? Looks like from code at
https://github.com/opscode/chef-provisioning/blob/master/lib/chef/provisioning/transport/ssh.rb#L313
that remote_host will not be assigned properly and that causes it to be nil, that causes the strange url to http::8889 be generated that causes the wrong config to uploaded that causes chef-client -l to fail with undefined method gsub on nil.

@jkeiser
Copy link
Contributor

jkeiser commented Jan 20, 2015

Got this (there is a patch now!). Working on getting backlog to the point where things are easier to respond to.

@franklinwise
Copy link

when I do "gem install chef-provisioning chef-provisioning-vagrant" I still get this problem... have the gems been updated?

@tyler-ball
Copy link
Contributor

If you install the latest ChefDK (0.4.0) do you still get this issue?

@atiniir
Copy link

atiniir commented Feb 10, 2015

I had this problem and 0.4.0 fixed it. (so happy). specifically i believe it's 0.18 of chef-provisioning which is included in chefdk 0.4.0

@christinedraper
Copy link
Contributor

Works for me too.

@tyler-ball
Copy link
Contributor

Woohoo! Okay, I'm going to close this unless @jkeiser or anyone else wants it open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants