Building a Vagrantfile with Chef provisioning not working - ruby

I'm trying to follow the following text tutorial and my setup breaks at the point where he types "bundle install", my setup did not install bundle so clearly there's something wrong with my Chef stuff - https://gorails.com/guides/using-vagrant-for-rails-development
edit: Why was this question downvoted? Did I fail to provide some background?
I ran the first two commands.
vagrant plugin install vagrant-vbguest
vagrant plugin install vagrant-librarian-chef-nochef
I created a folder and made a Cheffile and Vagrantfile like so:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Use Ubuntu 14.04 Trusty Tahr 64-bit as our operating system
config.vm.box = "ubuntu/trusty64"
# Configurate the virtual machine to use 2GB of RAM
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
# Forward the Rails server default port to the host
config.vm.network :forwarded_port, guest: 3000, host: 3000
# Use Chef Solo to provision our virtual machine
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apt"
chef.add_recipe "nodejs"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::vagrant"
chef.add_recipe "rbenv::user"
chef.add_recipe "vim"
chef.add_recipe "mysql::server"
chef.add_recipe "mysql::client"
# Install Ruby 2.2.1 and Bundler
# Set an empty root password for MySQL to make things simple
chef.json = {
rbenv: {
user_installs: [{
user: 'vagrant',
rubies: ["2.2.1"],
global: "2.2.1",
gems: {
"2.2.1" => [
{ name: "bundler" }
]
}
}]
},
mysql: {
server_root_password: ''
}
}
end
end
Cheffile
site "http://community.opscode.com/api/v1"
cookbook 'apt'
cookbook 'build-essential'
cookbook 'mysql', '5.5.3'
cookbook 'ruby_build'
cookbook 'nodejs'
cookbook 'rbenv', git: 'https://github.com/aminin/chef-rbenv'
cookbook 'vim'
I have spent 3 days so far fiddling with this all day and night and I cannot get it to work. I launch my vagrant box and bundler is not installed so I can't bundle install.
Clearly the chef.json is not working. I have tried pouring over the error output, I've been googling and have hundreds of tabs open, at this point I am completely lost.
In my chef.json, how does that work? How do I begin to find out how to craft my own chef.json? I don't understand it, how do I know to write user_installs for example?
Is there a difference between the following:
a) config.vm.provision :chef_solo do |chef|
b) config.vm.provision "chef solo" do |chef|
I can't even Google anything related to Chef and cookbooks because I get cooking results, you know, for FOOD.

Ahoy. There are a lot of questions up there.. so I'll try to go 1 at a time
*) Locally, did you install chef-client or chef dk?
Chefclient will not have bundler, where are chefdk does. It's also generally a smoother experience.
If you are using chef-client. You'll have to get bundler gem install bundler
If you are using chefdk. You'll either add chefdk ruby to your path, use temporary environment settings (eval "$(chef shell-init bash)") or just use chef exec bundle ...
*) Semi unrelated. But the comments on that blog go way back to 10+ months ago. I suggest you take a look at the https://learn.chef.io/index.html for the latest tutorials
*) chef_solo and 'chef solo' are different things. :chef_solo is a symbol. Think of it as thing that has special meaning within vagrant language. chef solo would have no meaning - a) it has a space in it, so it would be two different things - either variables (undefined in your example) or "chef solo" a string, which would have no meaning to the provisioner.
*) for googling chef related results, I suggest using http://docs.chef.io or including the name of the tool 'chef vagrant nil error'
Finally, applause for going off and learning this toolset. It's awesome, but a whole new universe.

Related

Automatically downloading & installing cookbooks on a vagrant box

I'm trying to create a Vagrant box that'll install some services when I run vagrant up.
For that purpose, I'm making use of these services:
Oracle VirtualBox
Chef Solo provisioner
Berkshelf
Vagrant Berkshelf Plugin
I'm using Berkshelf in order to handle cookbook dependencies.
The issues arise with certain cookbooks, which simply won't install.
Currently I'm trying to install nginx, from the cookbook I found on Chef Supermarket - nginx cookbook.
Berksfile:
source "https://supermarket.chef.io"
cookbook "nginx"
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "CentOS-6.5-minimal-0.1.1"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.hostname = "vagrant"
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
config.berkshelf.enabled = true
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks"]
chef.add_recipe "nginx"
end
end
I tried running vagrant provision with a combination of vagrant reload and shutting the box down and running vagrant up
The closest I've gotten to determining the cause of the problem is this stacktrace, I've gotten when running vagrant provision.
Any help for resolving this will be much appreciated.
The key issue here is you are using the Chef version that ships in Hashcorp's default boxes (Starting Chef Client, version 11.8.2). This version is too old to use the current nginx cookbook. You probably want to use the bento boxes which don't include a baked in version of Chef and then install it via Vagrant's omnibus support.

Vagrant Berkshelf could not find the 'berks' executable in your PATH. When running 'vagrant up'

$ vagrant up
Bringing machine 'district' up with 'virtualbox' provider...
Vagrant Berkshelf could not find the 'berks' executable in your PATH.
Please download and install the latest version of the ChefDK from:
https://downloads.getchef.com/chef-dk
and follow the installation instructions. Do not forget to add the ChefDK to
your PATH.
I downloaded the latest version of ChefDK as instructed.
How would I add the path to Berkshelf in the vagrant file?
Here is the my current Vgrantfile:
$ cat Vagrantfile
# vi: set ft=ruby :
Vagrant.configure('2') do |config|
config.vm.define 'district' do |app|
app.vm.box = 'ubuntu/trusty64'
app.vm.provider 'virtualbox' do |v|
v.memory = 1024
v.name = 'district'
end
app.ssh.forward_agent = true
app.vm.network :forwarded_port, guest: 4567, host: 4567
app.vm.synced_folder './', '/home/vagrant/WhatsMyDistrict'
app.berkshelf.enabled = true
app.vm.provision :chef_solo do |chef|
chef.log_level = :debug
chef.custom_config_path = 'chef_solo.config'
chef.run_list = ['whatsmydistrict::default']
end
end
end
Make sure you've added /opt/chefdk/bin to your $PATH.
It's recommended to have it prior to any ruby path locations - prepending is the easiest way to ensure this.
export PATH=/opt/chefdk/bin:$PATH
For Windows users ChefDK is installed in C:\opscode\chefdk\bin as explained here.
So you have to write this command line instead :
export PATH=/c/opscode/chefdk/bin:$PATH.
You can also follow these steps adding the path C:\opscode\chefdk\bin. You may have to restart your computer to apply the changes.

Why can't I install a vagrant environment with chef? certificate verify failed (OpenSSL::SSL::SSLError)

My environment:
OS: Mac 10.10.1
rbenv: rbenv 0.4.0-129-g7e0e85b
Ruby: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]
My Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Use Ubuntu 14.04 Trusty Tahr 64-bit as our operating system
config.vm.box = "precise32"
# Configurate the virtual machine to use 2GB of RAM
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
# Forward the Rails server default port to the host
config.vm.network :forwarded_port, guest: 3000, host: 3000
# Use Chef Solo to provision our virtual machine
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
chef.add_recipe "apt"
chef.add_recipe "nodejs"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::user"
chef.add_recipe "rbenv::vagrant"
chef.add_recipe "vim"
chef.add_recipe "mysql::server"
chef.add_recipe "mysql::client"
# Install Ruby 2.1.2 and Bundler
# Set an empty root password for MySQL to make things simple
chef.json = {
rbenv: {
user_installs: [{
user: 'vagrant',
rubies: ["2.1.2"],
global: "2.1.2",
gems: {
"2.1.2" => [
{ name: "bundler" }
]
}
}]
},
mysql: {
server_root_password: ''
}
}
end
end
My Cheffile:
site "http://community.opscode.com/api/v1"
cookbook 'apt'
cookbook 'build-essential'
cookbook 'mysql'
cookbook 'ruby_build'
cookbook 'nodejs', git: 'https://github.com/mdxp/nodejs-cookbook'
cookbook 'rbenv', git: 'https://github.com/fnichol/chef-rbenv'
cookbook 'vim'
After I run vagrant up, I got these errors:
➜ MY_RAILS_PROJECT vagrant up
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.5/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Installing Chef cookbooks with Librarian-Chef...
[default] Destroying VM and associated drives...
[default] Running cleanup tasks for 'chef_solo' provisioner...
/Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:800:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:800:in `block in connect'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/timeout.rb:100:in `timeout'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:800:in `connect'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:756:in `do_start'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /Users/jingqiangzhang/.vagrant.d/gems/gems/librarian-chef-0.0.4/lib/librarian/chef/source/site.rb:353:in `block in http_get'
I have found this article:
http://railsapps.github.io/openssl-certificate-verify-failed.html
I can confirm my openssl version:
➜ MY_RAILS_PROJECT openssl version
OpenSSL 1.0.1j 15 Oct 2014
I don't know what's the reason.
Change your site to https://supermarket.chef.io/api/v1. If that still fails, you'll need to update your TLS CA data. I'm not sure how Vagrant deals with this, but you can try using certifi if you have a working Python install:
pip install certifi
export SSL_CERT_FILE="$(python -m certifi)"

Puppet module install error - Directory /home/vagrant/.puppet/modules does not exist

I've got puppet working (with Vagrant) with a few of my own simple modules but i'm running into difficulty when trying to install modules from puppet forge.
VagrantFile:
Vagrant::Config.run do |config|
config.vm.box = "hashicorp/precise64"
config.vm.forward_port 80, 3000
config.vm.provision :puppet do |puppet|
puppet.module_path = "modules"
end
end
From inside my Virtual machine I am running:
puppet module install akandels-phpunit
I get the following error:
Error: Could not install module 'akandels-phpunit' (latest)
Directory /home/vagrant/.puppet/modules does not exist
I've seen one answer to Vagrant+Puppet puppet.module_path not working but it's not very clear.
I am using the basebox hashicorp/precise64 which is working fine with my own puppet modules.
What could be the problem here? Am I using puppet wrong? Thanks

Vagrant with librarian-chef installing ruby via ruby_build & rbenv

over the last few weeks i have had to reinstall my whole working environment a few times and it can take a while so now i have an ambitious idea to use vagrant and librarian-chef to create my working environment so that all i have to do is run a bash script and viola i am in.
so the first time i did this was solo vagrant i went in and did everything and packaged it and it was great for only a while.. the package was 600mb so next idea was to have chef do it all. but i have never worked with chef before so i found librarian-chef basically i librarian-chef init and it makes a cheffile that you can specify cookbooks mine looks like this
site 'http://community.opscode.com/api/v1'
cookbook 'apt'
cookbook 'git'
cookbook 'build-essential'
cookbook 'ruby_build',
git: 'git://github.com/fnichol/chef-ruby_build'
cookbook 'rbenv',
git: 'git://github.com/fnichol/chef-rbenv'
cookbook 'sqlite',
git: 'git://github.com/opscode-cookbooks/sqlite.git'
cookbook 'nodejs',
git: 'http://github.com/mdxp/nodejs-cookbook'
cookbook 'mysql',
git: 'git://github.com/opscode-cookbooks/mysql.git'
cookbook 'redis',
git: 'git://github.com/brianbianco/redisio.git'
cookbook 'zlib',
git: 'git://github.com/opscode-cookbooks/zlib'
cookbook 'wkhtmltopdf',
git: 'git://github.com/firstbanco/chef-wkhtmltopdf.git'
and you tell vagrant and chef to build these when you call vagrent up
in the vagrantfile
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks","site-cookbooks"]
chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "git"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::install"
chef.add_recipe "sqlite"
chef.add_recipe "nodejs"
chef.add_recipe "mysql"
chef.add_recipe "redis"
chef.add_recipe "zlib"
chef.add_recipe "wkhtmltopdf"
end
now i was wondering if i could get ruby_build to install 1.9.3-p290 i found this question which seemed to have the answer but i am getting the following
Running chef-solo...
stdin: is not a tty
[2013-05-23T14:31:18+00:00] INFO: *** Chef 10.14.2 ***
[2013-05-23T14:31:18+00:00] INFO: Setting the run_list to ["recipe[apt]", "recipe[build-essential]", "recipe[git]", "recipe[ruby_build]", "recipe[rbenv::install]", "recipe[sqlite]", "recipe[nodejs]", "recipe[mysql]", "recipe[redis]", "recipe[zlib]", "recipe[wkhtmltopdf]"] from JSON
[2013-05-23T14:31:18+00:00] INFO: Run List is [recipe[apt], recipe[build-essential], recipe[git], recipe[ruby_build], recipe[rbenv::install], recipe[sqlite], recipe[nodejs], recipe[mysql], recipe[redis], recipe[zlib], recipe[wkhtmltopdf]]
[2013-05-23T14:31:18+00:00] INFO: Run List expands to [apt, build-essential, git, ruby_build, rbenv::install, sqlite, nodejs, mysql, redis, zlib, wkhtmltopdf]
[2013-05-23T14:31:18+00:00] INFO: Starting Chef Run for precise64
[2013-05-23T14:31:18+00:00] INFO: Running start handlers
[2013-05-23T14:31:18+00:00] INFO: Start handlers complete.
================================================================================
Recipe Compile Error
================================================================================
Chef::Exceptions::RecipeNotFound
--------------------------------
could not find recipe ruby_build for cookbook rbenv
[2013-05-23T14:31:19+00:00] ERROR: Running exception handlers
[2013-05-23T14:31:19+00:00] ERROR: Exception handlers complete
[2013-05-23T14:31:19+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-05-23T14:31:19+00:00] FATAL: Chef::Exceptions::RecipeNotFound: could not find recipe ruby_build for cookbook rbenv
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
how can i get ruby installed as well through ruby build is it possible or is this not possible
Librarian will install your cookbooks locally, but they aren't transferred to the remote vagrant box. You'll need to use the Vagrant Librarian Chef plugin.
See also:
Berkshelf
Vagrant Berkshelf
try adding ruby_build to the run list:
"run_list": [ "ruby_build", "recipe[main]" ]

Resources