Skip to content

Instantly share code, notes, and snippets.

@mulderp
Created March 11, 2013 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mulderp/5135267 to your computer and use it in GitHub Desktop.
Save mulderp/5135267 to your computer and use it in GitHub Desktop.
cookbook rvm
class Chef::Resource::Script
def log_code command
if Chef::Config[:log_level] == :debug
code "{ #{command}; _ret=$?; echo \"Exit status was $_ret.\"; exit $_ret; } 2>&1 |
tee /var/log/#{@command.to_s.gsub(/ /,"_")}.log; exit ${PIPESTATUS[0]}"
else
code command
end
end
end
reqs = [
node[:rvm][:requirements][ node["platform"] ] ||
node[:rvm][:requirements][ node["platform_family"] ] ||
node[:rvm][:requirements][ node["os"] ]
].flatten * " && "
unless reqs.empty?
bash "install #{node["platform"]} requirements" do
if Chef::Config[:log_level] == :debug
puts "--- type: #{ node["platform"] } / #{ node["platform_family"] } / #{ node["os"] }"
puts "--- requirements: '#{reqs}'"
end
log_code reqs
end
end
installer_options="--auto-dotfiles"
rvm_command="/usr/local/rvm/bin/rvmsudo /usr/local/rvm/bin/rvm"
bash "install rvm" do
if File.directory? "/vagrant/rvm-src"
cwd "/vagrant/rvm-src"
log_code "./install #{installer_options}"
else
$stderr.puts "rvm-src not found falling back to download"
log_code "curl -L https://get.rvm.io | bash -s -- #{installer_options}"
end
end
%w( archives repos ).each do |type|
if File.directory? "/vagrant/rvm-#{type}"
bash "link rvm #{type}" do
log_code "rm -rf /usr/local/rvm/#{type} && ln -s /vagrant/rvm-#{type}/ /usr/local/rvm/#{type} "
end
else
$stderr.puts "rvm-#{type} missing, shared #{type} disabled"
end
end
bash "install rvm requirements" do
log_code "#{rvm_command} requirements run force"
end
node[:rvm][:binary][:versions].each do |version|
bash "uninstall #{version}" do
log_code "#{rvm_command} uninstall #{version}"
only_if "#{rvm_command} use #{version}"
end
bash "install #{version}" do
log_code "#{rvm_command} install #{version} --movable"
end
bash "package #{version}" do
cwd "/vagrant"
log_code "#{rvm_command} prepare #{version} --path"
end
end
deploy_user = 'vagrant' #node[:deploy][:user]
deploy_user_home = File.join('/', 'home', deploy_user)
rvm_version = "head"
execute "install_rvm_for_deploy_user" do
user deploy_user
command "curl -L https://get.rvm.io | bash -s #{rvm_version}"
environment "HOME" => deploy_user_home
creates "#{deploy_user_home}/.rvm"
end
#node['buildpack']['ruby_versions'].each do |ruby_version|
ruby_version = 'ruby-2.0.0-rc1'
execute "install_rvm_ruby_#{ruby_version}" do
user deploy_user
environment "HOME" => deploy_user_home
command "#{deploy_user_home}/.rvm/bin/rvm install #{ruby_version} --autolibs=3"
end
file "#{deploy_user_home}/.rvmrc" do
content 'export rvm_trust_rvmrcs_flag=1'
owner deploy_user
mode 0644
end
@mulderp
Copy link
Author

mulderp commented Mar 11, 2013

rb
[2013-03-11T16:00:32+00:00] DEBUG: Loading Recipe apt::default via include_recipe
[2013-03-11T16:00:32+00:00] DEBUG: Found recipe default in cookbook apt
[2013-03-11T16:00:32+00:00] DEBUG: Loading Recipe build-essential via include_recipe
[2013-03-11T16:00:32+00:00] DEBUG: Found recipe default in cookbook build-essential
[2013-03-11T16:00:32+00:00] DEBUG: Loading Recipe users via include_recipe
[2013-03-11T16:00:32+00:00] DEBUG: Found recipe default in cookbook users
[2013-03-11T16:00:32+00:00] DEBUG: Loading Recipe binary via include_recipe
[2013-03-11T16:00:32+00:00] DEBUG: Found recipe default in cookbook binary
--- type: ubuntu / debian / linux

--- requirements: 'sudo apt-get --quiet --yes update && sudo apt-get --no-install-recommends --quiet --yes install bash curl'

rvm-src not found falling back to download

rvm-archives missing, shared archives disabled

rvm-repos missing, shared repos disabled

[2013-03-11T16:00:32+00:00] DEBUG: Loading from cookbook_path: /tmp/vagrant-chef-1/chef-solo-1/cookbooks, /tmp/vagrant-chef-1/chef-solo-2/cookbooks
[2013-03-11T16:00:32+00:00] DEBUG: Converging node banking.pmdev
[2013-03-11T16:00:32+00:00] INFO: Processing execute[apt-get-update] action run (apt::default line 22)

@mulderp
Copy link
Author

mulderp commented Mar 11, 2013

After this operation, 1,639 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main libbison-dev amd64 1:2.5.dfsg-2.1 [33.3 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise/main bison amd64 1:2.5.dfsg-2.1 [295 kB]
Fetched 328 kB in 2s (119 kB/s)
Selecting previously unselected package libbison-dev.
(Reading database ... 61205 files and directories currently installed.)
Unpacking libbison-dev (from .../libbison-dev_1%3a2.5.dfsg-2.1_amd64.deb) ...
Selecting previously unselected package bison.
Unpacking bison (from .../bison_1%3a2.5.dfsg-2.1_amd64.deb) ...
Processing triggers for man-db ...
Setting up libbison-dev (1:2.5.dfsg-2.1) ...
Setting up bison (1:2.5.dfsg-2.1) ...
update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode.
[2013-03-11T16:01:07+00:00] DEBUG: STDERR:
[2013-03-11T16:01:07+00:00] DEBUG: ---- End output of apt-get -q -y install bison=1:2.5.dfsg-2.1 ----
[2013-03-11T16:01:07+00:00] DEBUG: Ran apt-get -q -y install bison=1:2.5.dfsg-2.1 returned 0
[2013-03-11T16:01:07+00:00] INFO: Processing bash[install ubuntu requirements] action run (binary::default line 27)
[2013-03-11T16:01:16+00:00] INFO: bash[install ubuntu requirements] ran successfully
[2013-03-11T16:01:16+00:00] INFO: Processing bash[install rvm] action run (binary::default line 38)
[2013-03-11T16:01:24+00:00] INFO: bash[install rvm] ran successfully
[2013-03-11T16:01:24+00:00] INFO: Processing bash[install rvm requirements] action run (binary::default line 58)
[2013-03-11T16:01:29+00:00] INFO: bash[install rvm requirements] ran successfully
[2013-03-11T16:01:29+00:00] INFO: Processing bash[uninstall ruby-1.9.3-p374] action run (binary::default line 63)
[2013-03-11T16:01:29+00:00] INFO: bash[uninstall ruby-1.9.3-p374] ran successfully
[2013-03-11T16:01:29+00:00] INFO: Processing bash[install ruby-1.9.3-p374] action run (binary::default line 67)

@mulderp
Copy link
Author

mulderp commented Mar 11, 2013

[2013-03-11T16:09:43+00:00] INFO: execute[install_rvm_for_deploy_user] ran successfully
[2013-03-11T16:09:43+00:00] INFO: Processing execute[install_rvm_ruby_ruby-2.0.0-rc1] action run (binary::default line 89)

================================================================================

Error executing action `run` on resource 'execute[install_rvm_ruby_ruby-2.0.0-rc1]'

================================================================================


Mixlib::ShellOut::ShellCommandFailed

------------------------------------

Expected process to exit with [0], but received '1'
---- Begin output of /home/vagrant/.rvm/bin/rvm install ruby-2.0.0-rc1 --autolibs=3 ----
STDOUT: Searching for binary rubies, this might take some time.
No binary rubies available for: ubuntu/12.04/x86_64/ruby-2.0.0-rc1.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing requirements for ubuntu/12.04/x86_64, might require sudo password
Updating repositories
Installing required packages: git-core........
STDERR: sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
No packages found matching git-core.
Error running 'requirements_debian_libs_install git-core',
please read /home/vagrant/.rvm/log/ruby-2.0.0-rc1/package_install_git-core.log
---- End output of /home/vagrant/.rvm/bin/rvm install ruby-2.0.0-rc1 --autolibs=3 ----
Ran /home/vagrant/.rvm/bin/rvm install ruby-2.0.0-rc1 --autolibs=3 returned 1


Resource Declaration:

---------------------

# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/binary/recipes/default.rb

 89:   execute "install_rvm_ruby_#{ruby_version}" do
 90:     user deploy_user
 91:     environment "HOME" => deploy_user_home
 92:     command "#{deploy_user_home}/.rvm/bin/rvm install #{ruby_version} --autolibs=3"
 93:   end
 94:

Compiled Resource:

------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/binary/recipes/default.rb:89:in `from_file'

execute("install_rvm_ruby_ruby-2.0.0-rc1") do
  action "run"
  retries 0
  retry_delay 2
  command "/home/vagrant/.rvm/bin/rvm install ruby-2.0.0-rc1 --autolibs=3"
  backup 5
  environment {"HOME"=>"/home/vagrant"}
  returns 0
  user "vagrant"
  cookbook_name :binary
  recipe_name "default"
end

[2013-03-11T16:09:46+00:00] DEBUG: Re-raising exception: Mixlib::ShellOut::ShellCommandFailed - execute[install_rvm_ruby_ruby-2.0.0-rc1] (binary::default line 89) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'

@mulderp
Copy link
Author

mulderp commented Mar 11, 2013

[2013-03-11T16:26:26+00:00] INFO: bash[package ruby-2.0.0-rc1] ran successfully
[2013-03-11T16:26:26+00:00] INFO: Processing execute[install_rvm_for_deploy_user] action run (binary::default line 80)
[2013-03-11T16:26:35+00:00] INFO: execute[install_rvm_for_deploy_user] ran successfully
[2013-03-11T16:26:35+00:00] INFO: Processing execute[install_rvm_ruby_ruby-2.0.0-p0] action run (binary::default line 89)

================================================================================

Error executing action `run` on resource 'execute[install_rvm_ruby_ruby-2.0.0-p0]'

================================================================================


Mixlib::ShellOut::ShellCommandFailed

------------------------------------

Expected process to exit with [0], but received '1'
---- Begin output of /home/vagrant/.rvm/bin/rvm install ruby-2.0.0-p0 --autolibs=3 ----
STDOUT: Searching for binary rubies, this might take some time.
ruby-2.0.0-p0 - #configure
ruby-2.0.0-p0 - #download
ruby-2.0.0-p0 - #validate archive
ruby-2.0.0-p0 - #extract
ruby-2.0.0-p0 - #validate binary
Mounting remote ruby failed, trying to compile.
Installing requirements for ubuntu/12.04/x86_64, might require sudo password
Updating repositories
Installing required packages: git-core........
STDERR: % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 18.9M  100 18.9M    0     0   516k      0  0:00:37  0:00:37 --:--:--  734k
Libraries missing for ruby-2.0.0-p0: libyaml-0.so.2. Refer to your system manual for installing libraries
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
No packages found matching git-core.
Error running 'requirements_debian_libs_install git-core',
please read /home/vagrant/.rvm/log/ruby-2.0.0-p0/package_install_git-core.log
---- End output of /home/vagrant/.rvm/bin/rvm install ruby-2.0.0-p0 --autolibs=3 ----
Ran /home/vagrant/.rvm/bin/rvm install ruby-2.0.0-p0 --autolibs=3 returned 1


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/binary/recipes/default.rb

 89:   execute "install_rvm_ruby_#{ruby_version}" do
 90:     user deploy_user
 91:     environment "HOME" => deploy_user_home
 92:     command "#{deploy_user_home}/.rvm/bin/rvm install #{ruby_version} --autolibs=3"
 93:   end
 94:

Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/binary/recipes/default.rb:89:in `from_file'

execute("install_rvm_ruby_ruby-2.0.0-p0") do
  action "run"
  retries 0
  retry_delay 2
  command "/home/vagrant/.rvm/bin/rvm install ruby-2.0.0-p0 --autolibs=3"
  backup 5
  environment {"HOME"=>"/home/vagrant"}
  returns 0
  user "vagrant"
  cookbook_name :binary
  recipe_name "default"
end

[2013-03-11T16:27:23+00:00] DEBUG: Re-raising exception: Mixlib::ShellOut::ShellCommandFailed - execute[install_rvm_ruby_ruby-2.0.0-p0] (binary::default line 89) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /home/vagrant/.rvm/bin/rvm install ruby-2.0.0-p0 --autolibs=3 ----
STDOUT: Searching for binary rubies, this might take some time.
ruby-2.0.0-p0 - #configure
ruby-2.0.0-p0 - #download
ruby-2.0.0-p0 - #validate archive
ruby-2.0.0-p0 - #extract
ruby-2.0.0-p0 - #validate binary

@mulderp
Copy link
Author

mulderp commented Mar 11, 2013

E: Unable to locate package update
vagrant@banking:~$ rvm --autolibs=3 requirements
Installing requirements for ubuntu/12.04/x86_64, might require sudo password
Updating repositories..............................................................................................
No packages found matching git-core.
Installing required packages: git-core.................................
No packages found matching libyaml-dev.
No packages found matching libsqlite3-dev.
No packages found matching sqlite3.
No packages found matching libxml2-dev.
No packages found matching libxslt-dev.
No packages found matching libgdbm-dev.
No packages found matching libffi-dev.
Installing required packages: libyaml-dev, libsqlite3-dev, sqlite3, libxml2-dev, libxslt-dev, libgdbm-dev, libffi-dev..............................................................
vagrant@banking:~$ rvm install 2.0.0
Searching for binary rubies, this might take some time.
ruby-2.0.0-p0 - #configure
ruby-2.0.0-p0 - #download
ruby-2.0.0-p0 - #validate archive
ruby-2.0.0-p0 - #extract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment