Search code examples
networkingcentosvagrantchefdk

berkshelf unable to connect on CentOS


I installed ChecfDK on the vagrant box.

Brekshelf is not work well. Uable to connet Unable to connect

I checked Iptables, etc, but could not find the problem on the network. URL is asccesable by curl, and work fine on ubuntu box.

CentOS (https://github.com/takase1024/chefdk-centos)

[vagrant@vagrant-centos65 ~]$ cd /vagrant/berks
[vagrant@vagrant-centos65 berks]$ berks install
Resolving cookbook dependencies...
Fetching 'myapp' from source at .
Fetching cookbook index from http://api.berkshelf.com/...
Error retrieving universe from source: http://api.berkshelf.com/
  * [Berkshelf::APIClient::TimeoutError] Unable to connect to: http://api.berkshelf.com/
E, [2014-08-25T03:14:08.122005 #1776] ERROR -- : Actor crashed!
Berkshelf::MissingLockfileCookbookVersion: Cookbook 'apache2' (2.0.0) not found in any of the sources! This can happen if the remote cookbook has been deleted or if the sources inside the Berksfile have changed. Please run `berks update apache2` to resolve to a valid version.
        /opt/chefdk/embedded/apps/berkshelf/lib/berkshelf/installer.rb:95:in `install'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `public_send'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:63:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:60:in `block in invoke'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:71:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/actor.rb:369:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks.rb:55:in `block in initialize'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
E, [2014-08-25T03:14:08.123992 #1776] ERROR -- : Actor crashed!
Berkshelf::MissingLockfileCookbookVersion: Cookbook 'iptables' (0.13.2) not found in any of the sources! This can happen if the remote cookbook has been deleted or if the sources inside the Berksfile have changed. Please run `berks update iptables` to resolve to a valid version.
        /opt/chefdk/embedded/apps/berkshelf/lib/berkshelf/installer.rb:95:in `install'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `public_send'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:63:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:60:in `block in invoke'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:71:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/actor.rb:369:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks.rb:55:in `block in initialize'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
Cookbook 'apache2' (2.0.0) not found in any of the sources! This can happen if the remote cookbook has been deleted or if the sources inside the Berksfile have changed. Please run `berks update apache2` to resolve to a valid version.

(Following omitted)

[vagrant@vagrant-centos65 berks]$ curl http://api.berkshelf.com/
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  <head>

(Following omitted)

Solution

  • After trying to use the Berkshelf workflow I came to figure out that it doesn't really work on vagrant (or I guess Virtual Box?) CentOS guests running on a Windows Host. This is because of the timeout issue as pointed out above. My hacky fix was this. I know its probably would be better to push an enhancement that allows you to pass this is as a variable.

    Now I am assuming you are using ChefDK's embedded ruby and berkshelf gem. If not, the locations might be in other places.

    Read more about the particular class here:

    http://ruby-doc.org/gems/docs/b/berkshelf-api-client-1.2.0/Berkshelf/APIClient/Connection.html

    [vagrant@vagrant-centos65 apache-acquity]$ cd /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/berkshelf-api-client-1.2.0/
    lib/berkshelf/api_client
    [vagrant@vagrant-centos65 api_client]$ vim connection.rb
    

    Find this:

    def initialize(url, options = {})
      options         = options.reverse_merge(retries: 3, retry_interval: 0.5,
        open_timeout: 3, timeout: 30)
    

    and change to this:

    def initialize(url, options = {})
      options         = options.reverse_merge(retries: 3, retry_interval: 0.5,
        open_timeout: 30, timeout: 30)
    

    Save and close and try it again.