Chef-client can't seem to run bundle install - ruby

I'm attempting to use the application_ruby cookbook to deploy my Rails app on a server Chef is setting up. When the chef-client reaches the point of running bundle install, it crashes, saying that it can't find bundler. I suspect this may have to do with the fact that I'm using RVM on this server, but I'm not sure what to do about that.
Here's my application recipe:
database_name = "app_#{node.chef_environment}"
api_deploy_key = Chef::EncryptedDataBagItem.load('keys', 'app_repository')["deploy_key"]
application "my_app" do
path "/var/www"
owner 'ubuntu'
repository "git#github.com:my_account/app.git"
revision node.chef_environment == "production" ? "master" : "develop"
deploy_key api_deploy_key
rails do
gems [['Bundler', '1.3.4']]
database_master_role 'db_master'
database do
database database_name
username "ubuntu"
password Chef::EncryptedDataBagItem.load('passwords', 'db')["password"]
end
bundler true
precompile_assets true
end
end
And this is the error that it produces:
================================================================================
Error executing action `run` on resource 'execute[bundle install --path=vendor/bundle --deployment --without development test cucumber production]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of bundle install --path=vendor/bundle --deployment --without development test cucumber production ----
STDOUT:
STDERR: /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:296:in `to_specs': Could not find 'bundler' (>= 0) among 175 total gem(s) (Gem::LoadError)
from /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:307:in `to_spec'
from /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:47:in `gem'
from /usr/local/rvm/gems/ruby-1.9.3-p125#global/bin/bundle:22:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `eval'
from /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `<main>'
---- End output of bundle install --path=vendor/bundle --deployment --without development test cucumber production ----
Ran bundle install --path=vendor/bundle --deployment --without development test cucumber production returned 1
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/application_ruby/providers/rails.rb
86: execute "#{bundle_command} install --path=vendor/bundle #{bundler_deployment ? "--deployment " : ""}--without #{common_groups}" do
87: cwd new_resource.release_path
88: user new_resource.owner
89: environment new_resource.environment
90: end
91: else
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/application_ruby/providers/rails.rb:86:in `block in class_from_file'
execute("bundle install --path=vendor/bundle --deployment --without development test cucumber production") do
action "run"
retries 0
retry_delay 2
command "bundle install --path=vendor/bundle --deployment --without development test cucumber production"
backup 5
cwd "/var/www/releases/30858f319060ca556b5109aa6d0ac64afa3f8e38"
environment {"RAILS_ENV"=>"staging", "PATH"=>"/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"}
returns 0
user "ubuntu"
cookbook_name "my_app"
end
If I set rollback_on_error to false, I can manually go into the checked-out code directory, and run bundle install without problems.
What's going wrong here, and how can I fix it?

you set your environment wrong, it should be:
environment {
"RAILS_ENV"=>"staging",
"PATH"=>"/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games",
"GEM_PATH"=>"/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125#global",
"GEM_HOME"=>"/usr/local/rvm/gems/ruby-1.9.3-p125"
}

Related

Error installing passenger: rake requires Ruby version >= 2.0.0. : Chef recipe error

I am trying to install passenger gem using chef recipe. Install methos is 'source'.
The ruby version installed is 2.2.3, and the gem binary is also specified as the same version.
But I am getting this error
STDERR: ERROR: Error installing passenger:
rake requires Ruby version >= 2.0.0.
When I tried to install directly in to the test VM it worked without any errors.
Any idea?
Chef Recipe
if node['nginx']['passenger']['install_method'] == 'package'
package node['nginx']['package_name']
package 'passenger'
elsif node['nginx']['passenger']['install_method'] == 'source'
gem_package 'passenger' do
action :install
version node['nginx']['passenger']['version']
gem_binary node['nginx']['passenger']['gem_binary'] if node['nginx']['passenger']['gem_binary']
end
node.run_state['nginx_configure_flags'] =
node.run_state['nginx_configure_flags'] | ["--add-module=#{node['nginx']['passenger']['root']}/ext/nginx"]
end
Test kitchen Log given below
Recipe: nginx::passenger
* apt_package[libcurl4-gnutls-dev] action install
- install version 7.35.0-1ubuntu2.17 of package libcurl4-gnutls-dev
* gem_package[passenger] action install
================================================================================
Error executing action `install` on resource 'gem_package[passenger]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /home/local/.rvm/rubies/ruby-2.2.3/bin/gem install passenger -q --no-rdoc --no-ri -v "4.0.57" ----
STDOUT:
STDERR: ERROR: Error installing passenger:
rake requires Ruby version >= 2.0.0.
---- End output of /home/local/.rvm/rubies/ruby-2.2.3/bin/gem install passenger -q --no-rdoc --no-ri -v "4.0.57" ----
Ran /home/local/.rvm/rubies/ruby-2.2.3/bin/gem install passenger -q --no-rdoc --no-ri -v "4.0.57" returned 1
Resource Declaration:
---------------------
# In /tmp/kitchen/cache/cookbooks/nginx/recipes/passenger.rb
39: gem_package 'passenger' do
40: action :install
41: version node['nginx']['passenger']['version']
42: gem_binary node['nginx']['passenger']['gem_binary'] if node['nginx']['passenger']['gem_binary']
43: end
44:
Compiled Resource:
------------------
# Declared in /tmp/kitchen/cache/cookbooks/nginx/recipes/passenger.rb:39:in `from_file'
gem_package("passenger") do
package_name "passenger"
action [:install]
retries 0
retry_delay 2
default_guard_interpreter :default
version "4.0.57"
declared_type :gem_package
cookbook_name "nginx"
recipe_name "passenger"
gem_binary "/home/local/.rvm/rubies/ruby-2.2.3/bin/gem"
end
Platform:
---------
x86_64-linux
Recipe: postfix::_common
* service[postfix] action restart
- restart service service[postfix]
Running handlers:
[2018-09-28T20:37:47+00:00] ERROR: Running exception handlers
Running handlers complete
[2018-09-28T20:37:47+00:00] ERROR: Exception handlers complete
Chef Client failed. 25 resources updated in 01 minutes 42 seconds
[2018-09-28T20:37:47+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
[2018-09-28T20:37:47+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-09-28T20:37:47+00:00] ERROR: gem_package[passenger] (nginx::passenger line 39) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /home/local/.rvm/rubies/ruby-2.2.3/bin/gem install passenger -q --no-rdoc --no-ri -v "4.0.57" ----
STDOUT:
STDERR: ERROR: Error installing passenger:
rake requires Ruby version >= 2.0.0.
---- End output of /home/local/.rvm/rubies/ruby-2.2.3/bin/gem install passenger -q --no-rdoc --no-ri -v "4.0.57" ----
Ran /home/local/.rvm/rubies/ruby-2.2.3/bin/gem install passenger -q --no-rdoc --no-ri -v "4.0.57" returned 1
[2018-09-28T20:37:47+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

travis failing to run rake with LoadError: cannot load such file -- rspec/core/rake_task

Let me preface this with this all runs locally and succeeds.
Source code repo
Travis log for job #4.1
Error:
$ rake
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
/home/travis/build/alienfast/gulp-pipeline-rails/Rakefile:4:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
/home/travis/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
.travis.yml
language: ruby
rvm:
- 2.2.2
- ruby-head
matrix:
allow_failures:
- rvm: ruby-head
cache: bundler
before_script:
# install Gulp 4 CLI tools globally from 4.0 GitHub branch
- npm install gulpjs/gulp-cli#4.0 -g
script: rake
Gemfile
gemspec
# travis-ci quirk?
group :development, :test do
gem 'rake'
gem 'rspec'
gem 'rspec-rails'
gem 'capybara'
gem 'capybara-webkit'
end
Fix attempts:
Locally, I have emptied my rvm gemset, deleted locks, and replicated the travis build - still works
I tried moving the necessary test gems from the gemspec to the Gemfile
So I'm pretty confused, I have other projects that don't have this problem and I don't see anything obvious. Is there any reason to get LoadError: cannot load such file -- rspec/core/rake_task?
Have you tried using bundle exec rake -t As noted here LoadError: cannot load such file -- rspec/core/rake_task

"Kitchen list" command fails with "Could not load the 'ssh' transport from the load path"

I'm trying to add a Test Kitchen to a Chef cookbook but am getting the error "Could not load the 'ssh' transport from the load path".
I have previously set up a Test Kitchen following the exact same steps without issue, but that was on a different machine.
I've tried running
gem install net-ssh
But that doesn't seem to fix the problem
Solved it.
I ran
gem list
Which gave the output
..
net-ssh (2.10.0.beta2, 2.9.2)
..
I then issued the command:
gem uninstall net-ssh 2.10.9.beta2
And got the output:
Select gem to uninstall:
1. net-ssh-2.10.0.beta2
2. net-ssh-2.9.2
3. All versions
Whereupon I selected option 1, the gem was removed and then running
kitchen list
Worked as expected
I was running into the same problem for Java SE Chef cookbook on Travis-CI with:
Chef Development Kit Version: 0.10.0
chef-client version: 12.6.0
berks version: 4.0.1
kitchen version: 1.5.0
Throwing this:
-----> Starting Kitchen (v1.5.0)
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ClientError
>>>>>> Message: Could not load the 'ssh' transport from the load path. Please ensure that your transport is installed as a gem or included in your Gemfile if using Bundler.
>>>>>> ----------------------
I had to switch to Dokken to get it to work:
https://github.com/someara/kitchen-dokken
To fix:
Update .travis.yml to install kitchen-dokken:
/opt/chefdk/embedded/bin/chef gem install kitchen-dokken
And update .kitchen.docker.yml with:
transport:
name: dokken
provisioner:
name: dokken
verifier:
root_path: '/opt/verifier'
sudo: false
driver:
name: dokken

Ruby on Rails, Deploy via Capistrano setup error

I am setting up Capistrano in a rails project for first time. When I run "cap production deploy:check" it goes OK. But when I run "cap prodution deploy" it gives back the following error...
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy#mysite.com: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory
SSHKit::Command::Failed: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory
Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy#mysite.com: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory
I am using rails 4.2.3. Ruby 2.2.2(with RVM). I have the following gems added for capistrano on Gemfile...
gem 'capistrano', '~> 3.4.0'
gem 'capistrano-rvm', '~> 0.1.2'
gem 'capistrano-bundler', '~> 1.1.4'
gem 'capistrano-rails', '~> 1.1.3'
gem 'capistrano3-unicorn', '~> 0.2.1'
You don't have the bundler gem installed on the server. The lines that look like this indicate that:
bundle stderr: /usr/bin/env: bundle: No such file or directory
You need to install the bundler gem on the server in order for capistrano to do it's thing.

Local ruby gems fail to install on Windows 2008R2: Errno::EADDRNOTAVAIL

Edit: Bug in rubygems 2.4.4. (fixed in 2.4.5)
I'm having trouble installing gems with the embedded ruby that comes with Chef Client v12.2.1, using the chef_gem resource:
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
chef_gem[zabbixapi] (generic_server_win::libzabbix-deps line 6) had an error: Mixlib::ShellOut::ShellCommand Failed: Expected process to exit with [0], but received '1'
---- Begin output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
STDOUT:
STDERR: ERROR: While executing gem ... (Errno::EADDRNOTAVAIL)
The requested address is not valid in its context. - connect(2)
---- End output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
Ran C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" returned 1
Also:
Same result when running the command manually on the command-line as an Administrator with the --local option
Same error occurs for other gems.
The servers that I'm trying to run this on have no internet access
I'm unable to reproduce the problem on a newly installed test machine (with internet access)
The version of ruby used is 2.0.0: ruby 2.0.0p451 (2014-02-24) [i386-mingw32]
Here is my Chef recipe:
cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
source 'zabbixapi-2.2.2.gem'
end
chef_gem "zabbixapi" do
source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end
You're problem is that the chef_gem resource is special in the way it enforce the use of the embedded ruby in chef installation and that it is run before convergence to allow the gem to be required in recipes. documentation about it here
To use a local source deployed with chef you have to ensure the file is present before, if not the gem command will try to download it (and fail with no internet access).
To ensure your local file is present before the chef_gem call you have to ensure the cookbook_file resource is called at compile time with this trick
in your specific case this should do:
cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
action :nothing
source 'zabbixapi-2.2.2.gem'
end.run_action(:create)
chef_gem "zabbixapi" do
source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end
The action nothing in the resource is to avoid having it called twice (once in compile phase and once in converge phase, even if the later won't have any impact, it's better to save time no evaluating it twice) then calling the action :create at end of the definition will trigger the action in the compile phase and the file will be present for the chef_gem call later.

Resources