Skip to content

Instantly share code, notes, and snippets.

@mudge
Created May 5, 2011 16:35
Show Gist options
  • Save mudge/957375 to your computer and use it in GitHub Desktop.
Save mudge/957375 to your computer and use it in GitHub Desktop.
Puppet class for a CentOS/RedHat server with RVM installed.
# rvm_server/manifests/init.pp
class rvm_server($version='latest') {
# Dependencies for RVM and Ruby.
package { 'rvm-dependencies':
ensure => installed,
name => ['bash', 'gawk', 'sed', 'grep', 'which', 'coreutils', 'tar',
'curl', 'gzip', 'bzip2', 'gcc-c++', 'autoconf', 'patch',
'readline', 'readline-devel', 'zlib', 'zlib-devel',
'libyaml-devel', 'libffi-devel', 'openssl-devel',
'glibc-headers', 'glibc-devel', 'libxml2', 'libxml2-devel',
'libxslt', 'libxslt-devel', 'curl-devel', 'mysql-devel'],
}
# Use RVM's installer to install our desired version. This will keep the installer
# around so we run it from /root
exec { 'rvm-install':
cwd => '/root',
command => "curl -s https://rvm.beginrescueend.com/install/rvm -o rvm-installer ; chmod +x rvm-installer ; ./rvm-installer --version ${version}",
unless => "grep ${version} /usr/local/rvm/VERSION",
path => '/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin',
require => Package['rvm-dependencies'],
}
file { '/usr/local/rvm/gemsets/global.gems':
ensure => present,
content => "rake\nbundler\n",
require => Exec['rvm-install'],
}
file { '/etc/gemrc':
ensure => present,
content => 'install: --no-rdoc --no-ri\nupdate: --no-rdoc --no-ri\n',
}
}
# A sample manifest using the RVM module.
include rvm_server
rvm_server::ruby { 'ruby19':
version => 'ruby-1.9.2-p180',
}
# rvm_server/manifests/ruby.pp
define rvm_server::ruby($version) {
exec { "rvm-ruby-install-${name}":
# Puppet seems to execute binaries directly without using a shell, so make sure
# to use bash for sourcing RVM's script before installing Ruby.
command => "bash -c 'source /usr/local/rvm/scripts/rvm ; rvm install ${version}'",
creates => "/usr/local/rvm/rubies/${version}",
# Be lenient as this needs to download, compile and install Ruby.
timeout => 1800,
path => '/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin',
# Depend on the global gemset being defined so that Ruby is installed
# with our default gems.
require => [File['/usr/local/rvm/gemsets/global.gems'], File['/etc/gemrc']],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment