I want to spin up a Vagrant box and provision a LAMP stack using chef-solo and berkshelf. Here's the steps I take:
berks cookbook my_project
Then in Berksfile:
site :opscode
cookbook 'wordpress', '~> 3.0.0'
cookbook 'apache2', '~> 3.2.2'
cookbook 'mysql', '~> 8.2.0'
cookbook 'php', '~> 2.2.0'
Then berks vendor cookbooks
The Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
Vagrant.require_version '>= 1.5.0'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.hostname = 'unify-config-berkshelf'
if Vagrant.has_plugin?("vagrant-omnibus")
config.omnibus.chef_version = 'latest'
end
config.vm.box = 'bento/ubuntu-14.04'
config.vm.network :private_network, type: 'dhcp'
config.vm.provision :chef_solo do |chef|
chef.json = {
mysql: {
server_root_password: 'rootpass',
server_debian_password: 'debpass',
server_repl_password: 'replpass'
}
}
chef.run_list = [
"recipe[apache2]",
"recipe[apache2::mod_php5]",
"recipe[mysql::client]",
"recipe[mysql::server]",
"recipe[php]",
"recipe[php::module_mysql]"
]
end
end
Then I try to bring the box up with vagrant up. This is the error I get.
The following berks command failed to execute:
/Users/stoebelj/.rbenv/shims/berks --version --format json
The stdout and stderr are shown below:
stdout:
stderr: Ignoring ffi-1.9.14 because its extensions are not built. Try: gem pristine ffi --version 1.9.14
Ignoring nokogiri-1.6.7.1 because its extensions are not built. Try: gem pristine nokogiri --version 1.6.7.1
Ignoring unf_ext-0.0.7.2 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.2
Ignoring wdm-0.1.1 because its extensions are not built. Try: gem pristine wdm --version 0.1.1
/Users/stoebelj/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'berkshelf' (>= 0.a) among 47 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/opt/vagrant/embedded/gems', execute `gem env` for more information
from /Users/stoebelj/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from /Users/stoebelj/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /Users/stoebelj/.rbenv/versions/2.3.1/bin/berks:22:in `<main>'
It appears that you are not using the ChefDK. Please note that Vagrant Berkshelf
works best when used with the ChefDK, and other installation methods are not
officially supported.
Please download and install the latest version of the ChefDK from:
https://downloads.chef.io/chef-dk
and follow the installation instructions. Do not forget to add the ChefDK to
your PATH.
I installed ChefDK from the URL given and /usr/local/bin/chef is in my PATH
What am I misunderstanding?
Update
A question below suggested I remove berkshelf from my rbenv, which did indeed get rid of the below error. Now I have a different error:
The Berkshelf version at "/usr/local/bin/berks" is invalid.
Vagrant Berkshelf requires >= 4.0, but the current version is .
Please download and install the latest version of the ChefDK from:
https://downloads.chef.io/chef-dk
and follow the installation instructions. Do not forget to add the ChefDK to
your PATH.
For context, I checked this which suggested I update my plugin. This did not work. I also tried removing the plugin and installing version 4.1 which also did not work.
And for context:
$ vagrant plugin list
vagrant-berkshelf (5.1.1)
vagrant-omnibus (1.5.0)
vagrant-share (1.1.6, system)
$ which berks
/usr/local/bin/berks
berks seems to work fine on its own but produces a warning I don't understand:
$ berks
W, [2017-02-13T13:46:00.590751 #3199] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.591227 #3199] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.591452 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.591672 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#frozen? defined in Kernel. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.629581 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#default defined in Hash. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
W, [2017-02-13T13:46:00.629737 #3199] WARN -- : You are setting a key that conflicts with a built-in method VariaModel::Attributes#default defined in Hash. This can cause unexpected behavior when accessing the key via as a property. You can still access the key via the #[] method.
Resolving cookbook dependencies...
Fetching 'unify_config' from source at .
Using apache2 (3.2.2)
Using build-essential (7.0.3)
Using compat_resource (12.16.3)
Using iis (5.0.5)
Using mingw (1.2.5)
Using mysql (8.2.0)
Using ohai (4.2.3)
Using php (2.2.0)
Using seven_zip (2.0.2)
Using unify_config (0.1.0) from source at .
Using windows (2.1.1)
Using xml (3.1.1)
Using yum-epel (2.1.1)
As shown in the command it is trying to run, the issue isn't the chef executable, it's berks. Remove the copy of that you installed via gems and makes sure the copy from ChefDK is working.
Ran into this issue couple days ago as well. Rolling back the version of ChefDK helped for me:
ChefDK 1.1.16
Coworker of mine was the one the dug up the reasoning, stating:
"vagrant uses berks -version --format json or something of the like to get the version of berks but running that command leads to some warning logs output by some dependency berks uses
which is why the version is blank"
Related
When I run Ruby scripts, I get 157 lines of warning messages like this:
/Users/clay/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/x86_64-darwin19/etc.bundle: warning: already initialized constant Etc::SC_AIO_LISTIO_MAX
/Users/clay/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/x86_64-darwin19/etc.bundle: warning: already initialized constant Etc::SC_AIO_MAX
/Users/clay/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/x86_64-darwin19/etc.bundle: warning: already initialized constant Etc::SC_AIO_PRIO_DELTA_MAX
... lots more
After some digging, it seems like the Ruby/gem/bundle industrial complex is using both the RVM version of Ruby 2.6.3 and the macOS system version of 2.6.3 in order to resolve the etc gem.
My hard-won quick-fix is to uninstall the rvm-ruby's etc gem, like:
rvm use 2.6.3
gem uninstall etc
However, anytime I initiate a gem update on this version of Ruby, etc will get reinstalled, and I'm back to a torrent o' warnings. I cannot get the system-ruby to uninstall etc at all.
Is there a more permanent fix?
Deets:
rvm 1.29.9
macOS Catalina 10.15.2
It appears I can suppress installing the etc gem in my Gemfile, like this:
source 'https://rubygems.org'
ruby '2.6.3'
gem 'cocoapods', '1.9.1'
# ... other gems
gem 'etc', :require => false
Because the system etc gem is already, um, "on the path", it all seems to work for now, but yikes, do not like.
I am install vagrant-librarian-chef in window 7, but it appear this error:
Installing the 'vagrant-librarian-chef' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:
An error occurred while installing chef (12.8.1), and Bundler cannot continue.
Make sure that gem install chef -v '12.8.1' succeeds before bundling.
Warning: this Gemfile contains multiple primary sources. Using source more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. To upgrade this warning to an error, run bundle config disable_multisource true.Errno::ENOENT: No such file or directory # dir_s_mkdir - C:/Users/tuan/.vagrant.d/gems/gems/chef-12.8.1-universal-mingw32/acceptance/top-cookbooks/test_run/learn-the-basics-ubuntu/cookbooks/learn-the-basics-ubuntu/.kitchen/kitchen-vagrant/kitchen-learn-the-basics-ubuntu-learn-the-basics-ubuntu-default-ubuntu-1404
Pls help me fix that.
Thanks all!
I was having a similar issue when using the 'ohai' ruby gem. I tried running gem install chef -v '12.8.1' but received an error. I fixed my problem by adding
gem 'chef-config', '~>12.7.2'
to my gemfile.
I looked at my gem dependency tree (gem dependency) and noticed the 'ohai' gem was trying to use chef-config 12.8, so I pinned it to an earlier version.
I'm trying to install and configure 'OpenShift' on Windows. I installed the necessary tools like: Git, RubyGem 2.x, but when I try to install 'rhc' ruby gem I got this error:
C:\>ruby -v
ruby 2.1.6p336 (2015-04-13 revision 50298) [x64-mingw32]
C:\>gem install rhc
ERROR: Could not find a valid gem 'rhc' (>= 0) in any repositor
C:\>
I've been searching this issue through the Internet, but it was unsuccessfully...
When I run the following command: $gem sources, I got this.
C:\>gem sources
*** CURRENT SOURCES ***
C:\>
It seems like something is wrong here, but yes, I did what you think. I "added" the source but...
C:\>gem source -a http://rubygems.org
[https://rubygems.org][1] is recommended for security over http://rubygems.org
Do you want to add this insecure source? [yn] y
Error fetching [http://rubygems.org][1]:
no such name (http://rubygems.org/specs.4.8.gz)
C:\>
What should I do guys? I've been reading so many forums and other webpages, but none of them gave me a solution to that.
Additional information: Windows 7 (x64), Ruby 2.1.6 (actually I had installed Ruby 2.2, but I found in some forums that this issue can fixed just back to and old version of Ruby). I use a proxy to connect me to Internet.
Updating info.
C:\>gem install rhc --source http://rubygems.org
ERROR: Could not find a valid gem 'rhc' (>= 0), here is why:
Unable to download data from http://rubygems.org/ - no such name (http://rubygems.org/specs.4.8.gz)
C:\>gem sources -c
*** Removed specs cache ***
C:\>gem sources -u
source cache successfully updated
C:\>gem install rhc --source http://rubygems.org
ERROR: Could not find a valid gem 'rhc' (>= 0), here is why:
Unable to download data from http://rubygems.org/ - no such name (http://rubygems.org/specs.4.8.gz)
C:\>
So the important information that you shared in your comments (you're behind a proxy) means that you will have to set some environment variables in order to use rubygems through the proxy.
In cmd.exe use:
set http_proxy=http://user:password#proxy_ip:port
or in PowerShell:
$env:http_proxy=http://user:password#proxy_ip:port
There was a case where that format didn't work and a different format had to be used:
http_proxy = proxy_ip:port
http_proxy_user = user
http_proxy_pass = password
Domain Users:
Try without the Domain prefix first, unless you know that the default Domain isn't set or that your Domain isn't the default.
Using a Domain User Login and the domain\user format, the \ must be replaced using its percent-encoding equivalent counterpart: %5C.
http://domain%5Cuser:password#proxy_ip:port
It looks like rubygems.org was having problems around the time you posted this question.
However, it should be fixed now.
I have a Sinatra app using Postgres via Activerecord. I'm using RVM on a Mac and a number of gems including:
activerecord
activesupport
When I run the server (thin), I get an error:
Could not load 'active_record/connection_adapters/postgresql_adapter'.
Make sure that the adapter in config/database.yml is valid. If you use
an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add
the necessary adapter gem to the Gemfile.
The adapter is set to postgresql in the config, and I've checked my RVM and paths: My Gem install path is set properly, and I can see the appropriate gems installed properly, and the specific adapter is there too, so really not sure what could be happening or how to further troubleshoot this?
Using Ruby 2.0.0-p598, activerecord and activesupport 4.1.4
--
Further debugging attempts:
ruby -v
ruby 2.0.0p598 (2014-11-13 revision 48408) [x86_64-darwin14.0.0]
which ruby
/Users/user/.rvm/rubies/ruby-2.0.0-p598/bin/ruby
gem env (relevant parts):
EXECUTABLE DIRECTORY: /Users/user/.rvm/gems/ruby-2.0.0-p598/bin
GEM PATHS:
/Users/user/.rvm/gems/ruby-2.0.0-p598
/Users/user/.rvm/gems/ruby-2.0.0-p598#global
SHELL PATH:
/Users/user/.rvm/gems/ruby-2.0.0-p598/bin
/Users/user/.rvm/gems/ruby-2.0.0-p598#global/bin
/Users/user/.rvm/rubies/ruby-2.0.0-p598/bin
ls $GEM_HOME/gems
activerecord-4.1.4
activesupport-4.1.4
Really at a loss for what else I can look into
database.yml
development:
adapter: postgresql
database: example_db
username: example_user
password: example_password
host: localhost
A next debugging step I took was to try using rvm to install a whole new version of ruby. This worked, so I used rvm to completely remove my old version of ruby with rvm remove 2.0.0-p598 and reinstall it again rvm install 2.0.0-p598.
I still have no idea what may have happened, but perhaps somehow something in the gem caches/builds were corrupted, so if anyone runs into a weird error like this where everything is in place but still doesn't work, try clearing everything with rvm and reinstalling.
I installed rbenv system wide (in /usr/local/rbenv) in my VPS.
And I want to install gems by using chef.
I tried like this, but the gem is installed in system default ruby.
gem_package "daemons" do
action :install
end
How can I install gems in system wide rbenv?
By following coderanger's advice, I installed rbenv cookbook by Berkshelf.
After that I edited recipe file like this:
include_recipe "rbenv::default"
include_recipe "rbenv::ruby_build"
rbenv_ruby "2.0.0-p451"
rbenv_gem "daemons" do
ruby_version "2.0.0-p451"
end
Then I got a error ERROR: No resource, method, or local variable named `rbenv_root_path' for `Chef::Recipe "default"'. How can I solve this problem?
You need to use the rbenv_gem resource.