Vagrant using Ruby 1.9.3 as default - ruby

Hey all i am trying to build a vagrant vm. i am using chef-solo for provisioning and chef-rbenv to manage my versions. so in the vagrantfile i specify
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::system"
chef.add_recipe "rbenv::vagrant"
...
chef.json = {
"rbenv" => {
"rubies" => [ "1.9.3-p327" ],
"global" => "1.9.3-p327",
"gems" => {
"1.9.3-p327" => [
{ "name" => "bundler" }
]
}
}
}
end
so that the default ruby version will be 1.9.3-p327, but it crashes
Error executing action `install` on resource 'rbenv_ruby[1.9.3-p327] (system)'
and if i dont specify the version in the vagrant file(as seen above), and go with the default rbenv that chef builds so that i can install it once i am in the vm. then i get this
vagrant#precise64:/vagrant$ rbenv install 1.9.3-p327
Downloading yaml-0.1.4.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...
BUILD FAILED
...
it works when i run sudo rbenv install 1.9.3-p327 but then when running anything i have to prefix it with sudo even ruby -v
vagrant#precise64:~$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
vagrant#precise64:~$ sudo ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.3.0]
how can i get it installed with chef-solo. i have tried all week and cant get it working at all.

The json requires you to specify for chef the rbenv location that your installing ruby to. since the recipes call that you install rbenv on a system level and then a user lvl in this case vagrant.
chef.add_recipe "rbenv::system"
chef.add_recipe "rbenv::vagrant"
So i went and changed the json to this:
chef.json = {
'rbenv' => {
'user_installs' => [
{
'user' => 'vagrant',
'rubies' => ['1.9.3-p327'],
'global' => '1.9.3-p327',
'gems' => {
'1.9.3-p327' => [
{ 'name' => 'bundler' },
{ 'name' => 'rake' }
]
}
}
]
}
}
Also the current rbenv cookbook often has bugs so its good to reference the latest taged version of the cookbook in the cheffile.
cookbook 'rbenv', git: 'git://github.com/fnichol/chef-rbenv.git', ref: "v0.7.2"
like so.

Related

Install Bundler gem with rbenv when provisioning (Chef + Vagrant)

I'm using Vagrant + Chef to provision an Ubuntu16.04 vm for rails development. I would like to install Bundler with Chef (using rbenv) but for some reason it fails with the following message: "undefined method `clear_sources' for Custom resource rbenv_gem from cookbook rbenv".
Any ideas?
Thanks!
The content of my Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
chef.add_recipe "apt"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::user"
chef.add_recipe "rbenv::vagrant"
chef.json = {
rbenv: {
user_installs: [{
user: 'vagrant',
rubies: ["2.3.1"],
global: "2.3.1" ,
gems: {
"2.3.1" => [
{ name: "bundler" }
]
}
}]
}
}
end
end
Cheffile:
site "https://supermarket.getchef.com/api/v1"
cookbook 'apt'
cookbook 'build-essential'
cookbook 'ruby_build', '~> 1.0.0'
cookbook 'rbenv', git: 'https://github.com/aminin/chef-rbenv'
You should use the official chef-rbenv cookbook, your issue was probably fixed by #110.
BTW. Any particular reason for not using test-kitchen?

vagrant puppet, composer unable to install laravel

I just recently knew about puppet and I'm trying to install laravel while vagrant is provisioning so that everything is already set (can be able to run laravel) when I logged in/ssh to vagrant. But I got stuck, it returned successfully executed but after I do vagrant ssh, laravel command is not available.
php5, php5-cli, etc. composer and other dependencies is already installed before this part of code.
class laravel {
Exec {
path => "/bin:/sbin:/usr/bin:/usr/sbin",
}
exec { "install-laravel" :
command => "/usr/local/bin/composer global require 'laravel/installer'",
require => [Package["php5-cli", "php5-dev"], Exec["install-composer", "set-composer-as-global"]],
cwd => "/home/vagrant/",
environment => ["COMPOSER_HOME=/home/vagrant"],
user => root,
group => root,
}
exec { "add-laravel-command" :
command => "mkdir /usr/local/bin/laravel",
environment => ["LARAVEL_HOME=/home/vagrant"],
onlyif => "test -d /usr/local/bin/composer",
require => Exec["install-laravel"],
user => root,
}
exec { "set-laravel-as-globall" :
command => "mv /home/vagrant/.composer/vendor/bin /usr/local/bin/laravel",
onlyif => "test -d /.composer/vendor/bin",
require => Exec["add-laravel-command"],
user => root,
}
}
Output
==> default: Notice: /Stage[main]/Laravel/Exec[install-laravel]/returns: executed successfully
==> default: Debug: /Stage[main]/Laravel/Exec[install-laravel]: The container Class[Laravel] will propagate my refresh event
==> default: Debug: Exec[add-laravel-command](provider=posix): Executing check 'test -d /usr/local/bin/composer'
==> default: Debug: Executing 'test -d /usr/local/bin/composer'
==> default: Debug: Exec[set-laravel-as-globall](provider=posix): Executing check 'test -d /.composer/vendor/bin'
==> default: Debug: Executing 'test -d /.composer/vendor/bin'
==> default: Debug: Class[Laravel]: The container Stage[main] will propagate my refresh event
Any help would be much appreciated. Thanks
create a file under puppet/modules/laravel/files and name it composer.json with the following content
{
"require": {
"laravel/installer": "^1.3"
}
}
Laravel init.pp file
class laravel {
Exec {
path => "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin",
user => root,
group => root,
}
file { "/usr/local/bin/laravel-devtools" :
ensure => directory,
owner => root,
group => root,
}
file { "/usr/local/bin/laravel-devtools/composer.json" :
source => "puppet:///modules/laravel/composer.json",
require => File["/usr/local/bin/laravel-devtools"],
owner => root,
group => root,
}
exec { "install-laravel" :
command => "sudo composer require 'laravel/installer'",
onlyif => "test -f /usr/local/bin/composer",
require => [
Package["nginx","php5-cli", "php5-dev", "php5-mysql"],
File["/usr/local/bin/laravel-devtools", "/usr/local/bin/laravel-devtools"],
],
environment => ["COMPOSER_HOME=/home/vagrant"],
cwd => "/usr/local/bin/laravel-devtools",
user => root,
group => root,
}
exec { "set-laravel-as-global" :
command => "sudo ln -s /usr/local/bin/laravel-devtools/vendor/laravel/installer/laravel /usr/local/bin/laravel",
require => [
File["/usr/local/bin/laravel-devtools", "/usr/local/bin/laravel-devtools/composer.json"],
Exec["install-laravel"],
],
}
}
Make sure composer is installed first during provision.

Vagrant/Puppet - Provision Failing (MySQL Not Working)

I have tried different virtual boxes, I have changed tons of configurations (probably recreated, reloaded and reprovisioned 50-100 times) -- it has to do with the MySQL module from Puppet -- which is apparently working for tens of thousands of others, so something I am doing is wrong.
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "puppetlabs/ubuntu-14.04-64-puppet"
# Was necessary
#vagrant plugin install vagrant-vbguest
# Networking
config.vm.network "forwarded_port", guest: 80, host: 8000
# config.vm.network "private_network", ip: "192.168.33.10"
# Synced folders
config.vm.synced_folder ".", "/var/www"
# Update
config.vm.provision "shell", inline: "apt-get -y update"
# Provisioning
config.vm.provision :shell do |shell|
shell.inline = "mkdir -p /etc/puppet/modules;
(puppet module install example42-puppi; true)
(puppet module install example42-apache; true)
(puppet module install example42-php; true)
(puppet module install puppetlabs-stdlib; true)
(puppet module install puppetlabs-mysql; true)
(puppet module install saz-vim; true)
(puppet module install saz-timezone; true)
(puppet module install puppetlabs-git; true)
(puppet module install tPl0ch-composer; true)
"
end
config.vm.provision "puppet" do |puppet|
puppet.facter = {
"fqdn" => "development.mydomain.com",
"aliases" => "*.development.mydomain.com",
"hostname" => "www",
"docroot" => '/var/www/html/',
}
puppet.hiera_config_path = "manifests/hiera.yaml"
puppet.working_directory = "/etc/puppet"
end
end
Puppet File: default.pp
###########################
# MySite Puppet Config #
###########################
# OS : Ubuntu 14 #
# Database : MySQL 5 #
# Web Server : Apache 2 #
# PHP version : 5.4 #
###########################
# Vim
class { 'vim': }
# Set Timezone
class { 'timezone':
timezone => 'America/Chicago',
}
# Puppi
class { 'puppi': }
# Apache setup
class { "apache":
puppi => true,
puppi_helper => "myhelper",
}
apache::vhost { $fqdn :
docroot => $docroot,
server_name => $fqdn,
serveraliases => $aliases,
priority => '',
template => 'apache/virtualhost/vhost.conf.erb',
}
apache::module { 'rewrite': }
apache::module { 'headers': }
# PHP Extensions
class {"php":}
php::module { ['xdebug', 'mysql', 'curl', 'gd', 'mcrypt']:
notify => Service['apache2']
}
# MySQL Server
class { '::mysql::server':
package_ensure => present,
root_password => '[root_password]',
override_options => { 'mysqld' => { 'default_time_zone' => 'America/Chicago' } },
}
class { 'mysql::client':}
mysql::db { '[db_name]':
user => '[user]',
password => '[password]',
host => 'localhost',
grant => ['ALL'],
charset => 'utf8',
}
exec { "database_import":
timeout => 300,
command => "/bin/gzip -dc /vagrant/manifests/provision.sql.gz | /usr/bin/mysql -u root -p[root_password]";
}
mysql::db { '[db_test]':
user => '[user_test]',
password => '[password_test]',
host => 'localhost',
grant => ['ALL'],
charset => 'utf8',
sql => "/var/www/test/db-schema.sql",
}
# Install Composer components
include composer
composer::exec { 'install':
cmd => 'install', # REQUIRED
cwd => '/var/www', # REQUIRED
dev => true, # Install dev dependencies
}
# Git
include git
# MySite Setup
file { $docroot:
ensure => 'directory',
}
$writeable_dirs = ["${docroot}cache/", "${docroot}cache/css/", "${docroot}cache/css/js/"]
file { $writeable_dirs:
ensure => "directory",
mode => '0777',
require => File[$docroot],
}
file { '/var/www/cl/':
ensure => directory
}
file { 'errors_log':
path => "/var/www/cl/errors.log",
ensure => present,
mode => 0777,
}
# Cron Jobs
cron { thirty_minutes:
command => "/usr/bin/php ${docroot}cl-load.php crons/thirty_minutes/",
user => root,
minute => '*/30'
}
cron { hourly:
command => "/usr/bin/php ${docroot}cl-load.php crons/hourly/",
user => root,
hour => '*',
minute => 0,
}
cron { four_hours:
command => "/usr/bin/php ${docroot}cl-load.php crons/four_hours/",
user => root,
hour => '*/4',
minute => 0,
}
cron { daily:
command => "/usr/bin/php ${docroot}cl-load.php crons/daily/",
user => root,
monthday => '*',
hour => '0',
minute => 0,
}
Here is the error message I am receiving (the first):
==> ==> default: Error: Could not start Service[mysqld]: Execution of '/sbin/start mysql' returned 1:
It seems that Puppet is trying to import the database before installing the MySQL server package.
Keep in mind that Puppet don't care about which resources you write first, if you need to manage something in a specific order you have to declare relationships explicitly. So in your case the following statement:
exec { "database_import":
timeout => 300,
command => "/bin/gzip -dc /vagrant/manifests/provision.sql.gz | /usr/bin/mysql -u root -p[root_password]",
require => Class['::mysql::server']
}
Could set the correct order for that resource. Possibly you'll need to declare additional relationships in a similar manner.

How can I install PHP APC via Pecl with Puppet

I am attempting to install PHP APC on Puppet but I do not know how to go about this? Pear is already installed and when I try and execute the command to install PHP APC I presented with an error message.
pecl.pp:
class php::pecl {
include php
exec { "pecl install php-apc":
require => Package["php-pear"]
}
}
pear.pp:
class php::pear {
include php
# upgrade PEAR
exec { "pear upgrade":
require => Package["php-pear"]
}
# install PHPUnit
exec { "pear config-set auto_discover 1":
require => Exec["pear upgrade"]
}
# create pear temp directory for channel-add
file { "/tmp/pear/temp":
require => Exec["pear config-set auto_discover 1"],
ensure => "directory",
owner => "root",
group => "root",
mode => 777
}
# discover channels
exec { "pear channel-discover pear.phpunit.de; true":
require => [File["/tmp/pear/temp"], Exec["pear config-set auto_discover 1"]]
}
exec { "pear channel-discover pear.symfony-project.com; true":
require => [File["/tmp/pear/temp"], Exec["pear config-set auto_discover 1"]]
}
exec { "pear channel-discover components.ez.no; true":
require => [File["/tmp/pear/temp"], Exec["pear config-set auto_discover 1"]]
}
# clear cache before install phpunit
exec { "pear clear-cache":
require => [Exec["pear channel-discover pear.phpunit.de; true"], Exec["pear channel-discover pear.symfony-project.com; true"], Exec["pear channel-discover components.ez.no; true"]]
}
# install phpunit
exec { "pear install -a -f phpunit/PHPUnit":
require => Exec["pear clear-cache"]
}
# install apc
exec { "pear install -a -f pear/php-apc":
require => Exec["pear clear-cache"]
}
}
php init.pp class:
class php {
# package install list
$packages = [
"php5",
"php5-cli",
"php5-mysql",
"php-pear",
"php5-dev",
"php5-gd",
"php5-mcrypt",
"libapache2-mod-php5",
]
package { $packages:
ensure => present,
require => Exec["apt-get update"]
}
}
Error message:
err: /Stage[main]/Php::Pear/Exec[pear install -a -f pear/php-apc]/returns: change from notrun to 0 failed: pear install -a -f pear/php-apc returned 1 instead of one of [0] at /tmp/vagrant-puppet-1/modules-0/php/manifests/pear.pp:52
err: /Stage[main]/Php::Pecl/Exec[pecl install php-apc]/returns: change from notrun to 0 failed: pecl install php-apc returned 1 instead of one of [0] at /tmp/vagrant-puppet-1/modules-0/php/manifests/pecl.pp:5
I would suggest that you use a tried and trusted puppet module which can install PHP and pecl extensions for you.
Have a look at the following puppet module which will most likely help.
https://forge.puppetlabs.com/example42/php
Turns out the package is actually called apc and not php-apc - doh!
Working code:
exec { "pecl install apc":
require => Exec["pear clear-cache"]
}

Vagrant File Chef Attributes

I am trying to configure my Vagrant file to have some chef attributes, but I must be doing something wrong because the chef recipes are using the defaults instead of my the attributes I am trying to set. Here is my config section of my vagrant file:
config.vm.provision :chef_solo do |chef|
chef.json = {
:mysql => {
:server_root_password => 'password'
},
:nodejs => {
:version => '0.6.14',
:dir => '/usr/local',
:npm => '1.1.13'
}
}
chef.cookbooks_path = "config/env/cookbooks"
chef.add_recipe "apt"
chef.add_recipe "mongodb::10gen_repo"
chef.add_recipe "mongodb"
chef.add_recipe "mysql::client"
chef.add_recipe "mysql::server"
chef.add_recipe "nodejs"
chef.add_recipe "nodejs::npm"
#chef.add_recipe "mymc_service"
end
Is my Ruby wrong or is there a better way to do this?
I'm brand new to Vagrant, Ruby, and Chef, but this is what worked for me:
config.vm.provision :chef_solo do |chef|
chef.json = {
"mysql" => {
"server_root_password" => "password"
}
}
chef.add_recipe "mysql" # etc
end
I recently ran into this same issue. While Mike's answer did not solve my problem, possibly due to the newer Vagrant/Chef versions, it pointed me in the right direction. The following is what i had to do for MySQL server to work:
config.vm.provision :chef_solo do |chef|
chef.json = {
:mysql => {
:server_root_password => "password",
:server_repl_password => "password",
:server_debian_password => "password"
}
}
chef.add_recipe "mysql::server"
end

Resources