run script after something changed an env variable (PATH)

38 views
Skip to first unread message

Massimo Galbusera

unread,
Aug 28, 2014, 5:17:38 AM8/28/14
to puppet...@googlegroups.com
Using https://github.com/maestrodev/puppet-rvm, I have this code to install a gem I copied in /tmp/mailcatcher.gem

rvm_gem { 'mailcatcher':
  name
=> 'mailcatcher',
  source
=> '/tmp/mailcatcher.gem',
  ruby_version
=> 'ruby-1.9.3-p547',
 
ensure => latest,
 
require => [
   
File['/tmp/mailcatcher.gem'],
   
Rvm_system_ruby['ruby-1.9.3-p547']
 
],
}


How can i run the installed gem script afterwards, with the new path set by ruby/rvm?
If i do this, it fails with "could not find command mailcatcher":

exec { 'start mailcatcher':
  command
=> "mailcatcher --http-ip=0.0.0.0",
 
require => Rvm_gem['mailcatcher'],
}


I need something to refresh the env variables, or something to get the new installed gem path.

I could hardcode the new path since i know which version of ruby i've installed:

exec { 'start mailcatcher':
  command => "mailcatcher --http-ip=0.0.0.0",
  require => Rvm_gem['mailcatcher'],
  cwd => "/usr/local/rvm/ruby-1.9.3-p547/bin/"
}

..but there must be a better way

Felix Frank

unread,
Aug 31, 2014, 11:17:35 AM8/31/14
to puppet...@googlegroups.com
On 08/28/2014 11:17 AM, Massimo Galbusera wrote:
I could hardcode the new path since i know which version of ruby i've installed:

exec { 'start mailcatcher':
  command => "mailcatcher --http-ip=0.0.0.0",
  require => Rvm_gem['mailcatcher'],
  cwd => "/usr/local/rvm/ruby-1.9.3-p547/bin/"
}

..but there must be a better way

I'm not so sure about that. Each exec resource inherits the agent's environment, and there is no simple way to change that (from within the manifest, no less).

It may be cleaner to use the environment parameter instead of cwd.

If you don't mind running Puppet twice, you could create a Fact to make sure that your command is not part of the catalog before the gem is ready for action.

HTH,
Felix
Reply all
Reply to author
Forward
0 new messages