Problem installing PEAR with a chef recipe for vagrant - ruby

I am using Vagrant to create a development server locally. I am writing my own Chef recipe to install everything I need but I am running into problems.
Pear will not install as I think it is trying to pull down a version that is not stable. The error is:
No such file or directory - pear -d preferred_state=stable search PEAR
The recipe is as follows
#
# Chef recipe for provisioning a LAMP
# development server.
#
require_recipe 'apt'
require_recipe 'apache2'
require_recipe 'apache2::mod_php5'
require_recipe 'php::module_gd'
require_recipe 'mysql::server'
php_pear "PEAR" do
action :upgrade
end
php_pear "MDB2" do
action :install
end
php_pear "MDB2#mysql" do
action :install
end
# Grant access to this box...
ruby_block "Create database + execute grants" do
block do
require 'rubygems'
Gem.clear_paths
require 'mysql'
m = Mysql.new('localhost', "root", node[:mysql][:server_root_password])
m.query("GRANT ALL ON *.* TO 'root'#'10.0.0.1' IDENTIFIED BY '#{node[:mysql][:server_root_password]}'")
m.query('FLUSH PRIVILEGES')
end
end
How can I make PEAR install the last stable version?

You are using pear to install pear itself? Isn't that strange?
The error message
No such file or directory
indicates that your recipe tries to use the full command as one executable, not as command and parameters.
pear -d preferred_state=stable search PEAR

Here's what I'm doing to upgrade PEAR in my Ubuntu VM:
package "php-pear" do
action :install
end
There's an Ubuntu package called php-pear, so this command will install the latest version

Related

chef windows_package encoding errors

I am trying to use Chef to install R onto windows 7.
I installed chef_handler and windows using knife
knife cookbook site install windows
knife cookbook site install chef_handler
and created a new cookbook
chef generate cookbook cookbooks/awesome_machine_config
inside default.rb I have
windows_package 'R for Windows 3.3.2' do
source 'd:/Downloads/R-3.3.2-win.exe'
action :install
end
inside metadata.rb
I have:
depends 'windows'
when I run:
chef-client --local-mode recipe[awesome_machine_config]
It synchronises the cookbooks fine and installs the cookbook gems fine.
But then I get a:
Error executing action `install` on resource 'windows_package[R for Windows 3.3.2]'
Encoding::InvalidByteSequenceError
incomplete "\x00" on UTF-16LE
chef is running as administrator so shouldn' be a permissions fault?
Any ideas how to debug?

Local ruby gems fail to install on Windows 2008R2: Errno::EADDRNOTAVAIL

Edit: Bug in rubygems 2.4.4. (fixed in 2.4.5)
I'm having trouble installing gems with the embedded ruby that comes with Chef Client v12.2.1, using the chef_gem resource:
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
chef_gem[zabbixapi] (generic_server_win::libzabbix-deps line 6) had an error: Mixlib::ShellOut::ShellCommand Failed: Expected process to exit with [0], but received '1'
---- Begin output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
STDOUT:
STDERR: ERROR: While executing gem ... (Errno::EADDRNOTAVAIL)
The requested address is not valid in its context. - connect(2)
---- End output of C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" ----
Ran C:/opscode/chef/embedded/bin/gem install c:/chef/cache/zabbixapi-2.2.2.gem -q --no-rdoc --no-ri -v "2.2.2" returned 1
Also:
Same result when running the command manually on the command-line as an Administrator with the --local option
Same error occurs for other gems.
The servers that I'm trying to run this on have no internet access
I'm unable to reproduce the problem on a newly installed test machine (with internet access)
The version of ruby used is 2.0.0: ruby 2.0.0p451 (2014-02-24) [i386-mingw32]
Here is my Chef recipe:
cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
source 'zabbixapi-2.2.2.gem'
end
chef_gem "zabbixapi" do
source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end
You're problem is that the chef_gem resource is special in the way it enforce the use of the embedded ruby in chef installation and that it is run before convergence to allow the gem to be required in recipes. documentation about it here
To use a local source deployed with chef you have to ensure the file is present before, if not the gem command will try to download it (and fail with no internet access).
To ensure your local file is present before the chef_gem call you have to ensure the cookbook_file resource is called at compile time with this trick
in your specific case this should do:
cookbook_file "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem" do
action :nothing
source 'zabbixapi-2.2.2.gem'
end.run_action(:create)
chef_gem "zabbixapi" do
source "#{Chef::Config[:file_cache_path]}/zabbixapi-2.2.2.gem"
end
The action nothing in the resource is to avoid having it called twice (once in compile phase and once in converge phase, even if the later won't have any impact, it's better to save time no evaluating it twice) then calling the action :create at end of the definition will trigger the action in the compile phase and the file will be present for the chef_gem call later.

How to install gems with system wide rbenv by using chef

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.

chef gem_package not using the right binary

I'm trying to install the gems "sensu_plugin" and "mixlib-shellout", on a windows server 2008r2, from a recipe. In this last one, I have the following code :
%w{ sensu-plugin mixlib-shellout }.each do |gem_plugin|
gem_package gem_plugin do
gem_binary("C:/opt/sensu/embedded/bin/gem")
options("--no-rdoc --no-ri")
action :install
end
end
Yet, when running the recipe on my machine, I receive the error "ERROR: While executing gem ... (Errno::ENOENT) No such file or directory - U:/". What I found out is that whenever I try installing a gem package using the gem binary located in the chef-client directory (C:\opscode\chef\embedded\bin\gem), it raised this last error.
The thing is that the gem I wish to use to installed the gem packages is actually located in C:/opt/sensu/embedded/bin/gem, which I have declared in the gem_binary option.
In the end it looks like chef is ignoring the gem_binary option and trying to install it from its own gem binary.
I can't see what's wrong with this config. Is the gem_binary really indicating what binary to use?

vagrant will not use rbenv ruby version

I'm using the Vagrant box:
https://dl.dropbox.com/u/14292474/vagrantboxes/precise64-ruby-1.9.3-p194.box
It has ruby1.9.3 installed under rbenv. I'm trying to test a rails app and in the chef-solo provisioner I have (among other things), this block:
execute 'install' do
action :run
command "bundle install --path #{node.app_name.lib_path}/vendor/bundle --binstubs"
cwd node.app_name.path
end
rbenv is installed under the vagrant user and instructed to use 1.9.3 globally. For some reason, when bundler is run during vagrant up it still uses 1.8.7 which is only found in /opt/vagrant_ruby.
How can I tell vagrant that I want to use the rbenv ruby to perform all tasks. Do I need to pass something in the env option of the execute block?
First start to get the path of bundle in your server:
$ which bundle
/opt/rbenv/shims/bundle
Then, knowing that in chef when you included the rbenv cookbook, the constant RBENV_ROOT is equal to /opt/rbenv, modify your command like this:
command "#{RBENV_ROOT}/shims/bundle install --path #{node.app_name.lib_path}/vendor/bundle --binstubs"
So you ensure to use the correct version of bundle when installing.
A second thing you can do is to add the path for rbenv (which can be located in /etc/profile.d/rbenv but that depends on your installation) on top of the ~/.bashrc of the user you use with chef-solo
For example, if you are using a use "deployer", edit /home/deployer/.bashrc to have on top of the file:
#Rbenv path for remote shells
source /etc/profile.d/rbenv.sh # <--- adapt this to your installation
# If not running interactively, don't do anything
[ -z "$PS1" ] && return # <--- remote shell (ssh connection) will stop at this line

Resources