Vagrant with librarian-chef installing ruby via ruby_build & rbenv - ruby

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]" ]

Related

Chef solo with berkshelf: cookbook not resolved

I've created this Vagrantfile's provioner section:
config.vm.provision "chef_solo" do |chef|
chef.add_recipe "wildfly"
end
I'm getting this error:
==> default: Error Resolving Cookbooks for Run List:
==> default:
==> default: Missing Cookbooks:
==> default: ------------------
==> default: No such cookbook: wildfly
So, I've created a Berksfile and a metadata.rb files:
Berksfile:
source 'https://supermarket.chef.io'
metadata
metadata.rb:
name 'webapi'
maintainer 'The Authors'
maintainer_email 'you#example.com'
license 'all_rights'
description 'Installs/Configures webapi'
long_description 'Installs/Configures webapi'
version '0.1.0'
depends 'java_se', '~> 9.0.1'
depends 'wildfly', '~> 0.4.0'
So, then I've performed berks install command. The first issue I've detected is that I don't quite detect where berks has placed cookbooks. It seems that it works right, nevertheless, I don't find where cookbooks dependencies are located, I mean, a .\cookbooks folder is not created after performing berks install command.
Resolving cookbook dependencies...
Fetching 'olingo' from source at .
Fetching cookbook index from https://supermarket.chef.io...
Using apt (6.1.4)
Using homebrew (4.2.0)
Using java (1.50.0)
Using java_se (9.0.1)
Using ohai (5.2.0)
Using olingo (0.1.0) from source at .
Using wildfly (0.4.0)
Using yum (5.1.0)
Using windows (3.4.0)
Regardless of that, I've performed vagrant provision again, and wildfly cookbook is not resolved:
The cookbook path 'D:/projects/swiller/querydsl/olingo/infrastructure/cookbooks' doesn't exist. Ignoring...
Running provisioner: chef_solo...
==> default: Error Resolving Cookbooks for Run List:
==> default:
==> default: Missing Cookbooks:
==> default: ------------------
==> default: No such cookbook: wildfly
You either need to use the vagrant-berkshelf plugin, or use the berks vendor command to write all the cookbooks to a folder and then point Vagrant at that (which is what the plugin does internally). berks install only downloads them to your workstation, it doesn't put the cookbooks in a place/format that anything other than Berkshelf understands.

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.

Installing mysql2 gem in vagrant via chef-solo

I'm trying to install mysql2 gem in my vagrant machine with chef solo. I am getting the following error
ERROR: mysql2_chef_gem_installer[default] (mysql2_chef_gem::default line 20) had an error:
Chef::Exceptions::RecipeNotFound: could not find recipe client for cookbook mysql
I have included the cookbook mysql and the dependencies are added in the metadata.rb
Following is the code snippet
mysql2_chef_gem_installer 'default' do
type 'mysql'
action :install
end
Could somebody explain what is it I am doing wrong ?

Building a Vagrantfile with Chef provisioning not working

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.

Problems running Vagrant/Puppet on osx 10.7

I'm just getting started with Vagrant and Puppet. I'm able to get a Virtualbox running but now I want to automate the software that gets installed on it.
In my Vagrantfile I have:
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.forward_port 80, 9090
config.vm.forward_port 27017, 27017
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "default.pp"
end
end
in manifests/default.pp I have:
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
class php5{
package { "php5":
ensure => present,
}
}
include php5
However, when I run vagrant up I get the following error (snippet).
[default] Running Puppet with /tmp/vagrant-puppet/manifests/default.pp...
stdin: is not a tty
No LSB modules are available.
warning: Could not retrieve fact fqdn
err: /Stage[main]/Php5/Package[php5]/ensure: change from purged to present failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install php5' returned 100: Reading package lists...
I'm not really sure where the error lies, so here is some further information which might be useful
Ruby version
$ ruby -v
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
gem sources
$ gem sources
*** CURRENT SOURCES ***
http://rubygems.org/
Update 1: Following this post I installed facter and puppet now runs ok but the main problem is still happening.
Update 2: Correct answer marked, but I wanted to share my entire manifest file http://pastebin.com/LGNhVPV7
The 'apt-get install' error is probably happening because the VM hasn't finished an 'apt-get update' before Puppet tries to do the 'apt-get install'. Puppet won't handle the 'apt-get update' on its own when you request that a package be installed, but you can spell out that it should happen in your manifest easily enough.
Try adding the apt class Mr Leach mentions in his http://johnleach.co.uk/words/771/puppet-dependencies-and-run-stages post. This should ensure that 'apt-get update' is run before any packages are installed.

Resources