puppet-rbenv icon indicating copy to clipboard operation
puppet-rbenv copied to clipboard

source .rbenvrc breaks for non-interactive shells

Open bjoernalbers opened this issue 13 years ago • 7 comments

Installing rbenv with:

rbenv::install { $user:
  require => User[$user],
  rc      => '.bashrc',
}

...works not for non-login shells:

deployer@precise32:~$ which ruby
/home/deployer/.rbenv/shims/ruby
deployer@precise32:~$ exit
logout
Connection to 127.0.0.1 closed.
$ ssh [email protected] -p 2222 
which ruby
$ echo $?
1

...because .bashrc does only source .rbenvrc for interactive shells:

deployer@precise32:~$ egrep -A 1 '(interactive|rbenv)' .bashrc
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
--
source /home/deployer/.rbenvrc

Placing the source statement earlier would of course solve this.

bjoernalbers avatar Oct 18 '12 21:10 bjoernalbers

This issue came up during a capistrano deployment when running bundler over ssh on the deployment machine.

bjoernalbers avatar Oct 18 '12 21:10 bjoernalbers

PS: great module (saved me a ton of time)!

bjoernalbers avatar Oct 18 '12 21:10 bjoernalbers

Did you try using the .profile instead of .bashrc? This should fix your problem.

alup avatar Oct 21 '12 21:10 alup

@alup Thanks for having a look at this!

Unfortunately bash doesn't care about a my .profile when running over ssh (see bash(1)):

Bash attempts to determine when it is being run with its standard input connected to a net-
work connection, as when executed by the remote shell daemon, usually rshd, or  the  secure
shell  daemon  sshd.  If bash determines it is being run in this fashion, it reads and exe-
cutes commands from ~/.bashrc and ~/.bashrc, if these files exist  and  are  readable.

I'll fix this in my fork. Just send me a line, if you want to have a pull request.

bjoernalbers avatar Oct 22 '12 18:10 bjoernalbers

@bjoernalbers Is this still an issue?

fgrehm avatar Jan 29 '13 19:01 fgrehm

I was just having difficulties with my rbenv install command and switching over to @bjoernalbers fork solved my problem without having to change anything else. This was with a CentOS 6.3 image.

cloudshark avatar Feb 08 '13 03:02 cloudshark

I added this step to my manifest, it may be worth adding into the rbenv module itself. It worked around the .bashrc / .bash_profile / .profile problem for me.

file { '/etc/profile.d/rbenv.sh':
  ensure  => present,
  mode    => '0644',
  owner   => 'root',
  group   => 'root',
  content => '[ -e ~/.rbenvrc ] && . ~/.rbenvrc'
}

ghost avatar May 29 '13 17:05 ghost

I was seeing the .profile get loaded on Ubuntu 14.x but not on CentOS 6.5 and @ghost's code to init.pp and then 'require ::rbenv' to rbenv::install makes it work on my nodes. I'll submit a PR if I get some time.

nvalentine-puppetlabs avatar Jun 18 '14 20:06 nvalentine-puppetlabs