Created
August 29, 2012 22:09
-
-
Save mzupan/3519525 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following part is optional! It just compiles and installs the chosen | |
# global ruby version to help on bootstrapping. To achieve this, it uses | |
# "ruby-build" utility. | |
define rbenv::compile($user,$global_ruby="1.9.2-p290",$bundler_version='1.1.3') { | |
# STEP 1 | |
exec { "checkout rbenv for ${user}": | |
command => "git clone git://github.com/sstephenson/rbenv.git .rbenv", | |
user => $user, | |
cwd => "/home/${user}", | |
creates => "/home/${user}/.rbenv", | |
path => ["/usr/bin", "/usr/sbin"], | |
require => Package['git-core'], | |
} | |
# STEP 2 | |
exec { "checkout ruby-build for ${user}": | |
command => "git clone git://github.com/sstephenson/ruby-build.git", | |
user => $user, | |
cwd => "/home/${user}", | |
creates => "/home/${user}/ruby-build", | |
path => ["/usr/bin", "/usr/sbin"], | |
timeout => 100, | |
require => [Package['git-core'], Exec["checkout rbenv for ${user}"]] | |
} | |
# STEP 3 | |
exec { "install ruby-build for ${user}": | |
command => "sh install.sh", | |
user => "root", | |
group => "root", | |
cwd => "/home/${user}/ruby-build", | |
onlyif => '[ -z "$(which ruby-build)" ]', | |
path => ["/bin", "/usr/local/bin", "/usr/bin", "/usr/sbin"], | |
require => Exec["checkout ruby-build for ${user}"] | |
} | |
# Set Timeout to disabled cause we need a lot of time to compile. | |
# Use HOME variable and define PATH correctly. | |
exec { "install ruby ${global_ruby} for ${user}": | |
command => "rbenv-install ${global_ruby}", | |
timeout => 0, | |
user => $user, | |
cwd => "/home/${user}", | |
environment => [ "HOME=/home/${user}" ], | |
onlyif => ['[ -n "$(which rbenv-install)" ]', "[ ! -e /home/${user}/.rbenv/versions/${global_ruby} ]"], | |
path => ["/home/${user}/.rbenv/shims", "/home/${user}/.rbenv/bin", "/bin", "/usr/local/bin", "/usr/bin", "/usr/sbin"], | |
require => [Package['curl'], Exec["install ruby-build for ${user}"]], | |
} | |
exec { "set-global_ruby for ${user}": | |
command => "rbenv global ${global_ruby}", | |
user => $user, | |
cwd => "/home/${user}", | |
environment => [ "HOME=/home/${user}" ], | |
onlyif => '[ -n "$(which rbenv)" ]', | |
unless => "grep ${global_ruby} /home/${user}/.rbenv/version 2>/dev/null", | |
path => ["/home/${user}/.rbenv/shims", "/home/${user}/.rbenv/bin", "/bin", "/usr/local/bin", "/usr/bin", "/usr/sbin"], | |
require => Exec["install ruby ${global_ruby} for ${user}"], | |
} | |
exec { "install rbenv bundler for ${user}": | |
command => "gem install bundler --version=${bundler_version} --no-ri -- no-rdoc", | |
user => $user, | |
cwd => "/home/${user}", | |
environment => [ "HOME=/home/${user}" ], | |
onlyif => '[ -n "$(which rbenv)" ]', | |
unless => "gem list | grep bundler | grep ${bundler_version}", | |
path => ["/home/${user}/.rbenv/shims", "/home/${user}/.rbenv/bin", "/bin", "/usr/local/bin", "/usr/bin", "/usr/sbin"], | |
require => Exec["set-global_ruby for ${user}"], | |
notify => Exec["rehash-rbenv for ${user}"], | |
} | |
exec { "rehash-rbenv for ${user}": | |
command => "rbenv rehash", | |
user => $user, | |
cwd => "/home/${user}", | |
environment => [ "HOME=/home/${user}" ], | |
# onlyif => '[ -n "$(which rbenv)" ]', | |
path => ["/home/${user}/.rbenv/shims", "/home/${user}/.rbenv/bin", "/bin", "/usr/local/bin", "/usr/bin", "/usr/sbin"], | |
# require => Exec["install rbenv bundler for ${user}"], | |
refreshonly => true, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment