From 649d87c3282ba52f40a3f947bb68bc53571757a4 Mon Sep 17 00:00:00 2001 From: Dean Smith Date: Sat, 1 Feb 2014 14:57:37 +0000 Subject: [PATCH 1/3] Adding support for setting default ruby for a user --- README.md | 7 +++++++ manifests/default.pp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 manifests/default.pp diff --git a/README.md b/README.md index 5af60c0..16e2c68 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ Install a couple of Rubies single_user_rvm::install_ruby { 'ruby-1.9.3-p392': user => 'username' } single_user_rvm::install_ruby { 'ruby-2.0.0-p247': user => 'username' } +Set the default ruby +-------------------- + + single_user_rvm::default {'ruby-1.9.3': user => 'username' } + +ruby-1.9.3 is a grep match on the output of rvm current + More info in [install_ruby.pp](manifests/install_ruby.pp) License diff --git a/manifests/default.pp b/manifests/default.pp new file mode 100644 index 0000000..8663ae6 --- /dev/null +++ b/manifests/default.pp @@ -0,0 +1,42 @@ +# == Define: single_user_rvm::default +# +# Sets the default RVM ruby +# +# # === Parameters +# +# # [*ruby_string*] +# Ruby version to install, be sure to use the full Ruby string as failing to do so will break the mechanism that +# detects if the required ruby is already installed. Defaults to the value of the title string. +# Should match a ruby installed by single_user_rvm::install_ruby +# +# [*user*] +# The user for which this Ruby will be installed. Defaults to 'rvm'. +# +# === Examples +# +# Set Ruby 2.0.0 p247 as default for user 'dude': +# +# single_user_rvm::default { 'ruby-2.0.0-p247': +# user => 'dude', +# } +# +define single_user_rvm::default ( + $user ='rvm') { + + if $home { + $homedir = $home + } else { + $homedir = "/home/${user}" + } + + + $command = "${homedir}/.rvm/bin/rvm use --default ${title}" + $check_command = "${homedir}/.rvm/bin/rvm current | grep ${title}" + + exec { "su -c '${command}' - ${user}": + path => "/usr/bin:/usr/sbin:/bin", + require => Single_user_rvm::Install[$user], + unless => "su -c '${check_command}' - ${user}" + } + } + From 987c0943563f011378722068207a4985ac088b6d Mon Sep 17 00:00:00 2001 From: Dean Smith Date: Mon, 3 Feb 2014 10:59:44 +0000 Subject: [PATCH 2/3] Now working version of last commit --- manifests/default.pp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/manifests/default.pp b/manifests/default.pp index 8663ae6..bbe6a80 100644 --- a/manifests/default.pp +++ b/manifests/default.pp @@ -30,13 +30,18 @@ } - $command = "${homedir}/.rvm/bin/rvm use --default ${title}" - $check_command = "${homedir}/.rvm/bin/rvm current | grep ${title}" + $command = "rvm use --default ${title}" + $check_command = "rvm current" - exec { "su -c '${command}' - ${user}": - path => "/usr/bin:/usr/sbin:/bin", + exec { "su -l ${user} -c '${command}'": + path => "/usr/bin:/usr/sbin:/bin:~/.rvm/bin", + provider => shell, + logoutput => true, + cwd => "/home/${user}", require => Single_user_rvm::Install[$user], - unless => "su -c '${check_command}' - ${user}" + unless => "su -l ${user} -c '${check_command}' | grep ${title}" + } + + } - } From 057244e9e16ba3be3d55c19f0a2821a56a93cbad Mon Sep 17 00:00:00 2001 From: Dean Smith Date: Mon, 3 Feb 2014 11:08:59 +0000 Subject: [PATCH 3/3] Don't log output --- manifests/default.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/default.pp b/manifests/default.pp index bbe6a80..95b0be2 100644 --- a/manifests/default.pp +++ b/manifests/default.pp @@ -36,7 +36,7 @@ exec { "su -l ${user} -c '${command}'": path => "/usr/bin:/usr/sbin:/bin:~/.rvm/bin", provider => shell, - logoutput => true, + logoutput => false, cwd => "/home/${user}", require => Single_user_rvm::Install[$user], unless => "su -l ${user} -c '${check_command}' | grep ${title}"