Environment variables can be set as you described when using "run". Unfortunately, it's trickier when using sudo. :( For now, the easiest way to do it with sudo is to create a shell script that sets the environment and runs the commands, and invoke that script via sudo.
You can always do: run "PATH=/foo/bar sudo env" but the problem with that approach is that Capistrano doesn't know you're running sudo, and so won't know to prompt for a password and such. :( - Jamis On Jan 23, 2007, at 3:55 PM, Mathieu Lajugie wrote: > > It works great, thanks! > > I guess I should have looked at the changelog first... > > Is there also a way to set environment variables before running a > command, like PATH? It is ok to do: > > run "PATH=/my/path/to/bin:$PATH env | grep PATH" > > But doing the same with sudo fails because: > > sudo "PATH=/my/path/to/bin:$PATH env | grep PATH" > > executes: > > run "sudo PATH=/my/path/to/bin:$PATH env | grep PATH" > > when it actually should execute: > run "PATH=/my/path/to/bin:$PATH sudo env | grep PATH" > > Thanks again for Capistrano, your blog and Rails! > > > --mathieul > > > On Jan 23, 2007, at 12:24 PM, Jamis Buck wrote: > >> >> mathieul, >> >> You can actually do this: >> >> task :my_test, :hosts => "linux7" do >> ... >> end >> >> That will then execute that task _specifically_ and _only_ on the >> linux7 host. Does that work for you? >> >> - Jamis >> >> On Jan 23, 2007, at 12:18 PM, mathieul wrote: >> >>> >>> Hello, >>> >>> I'm pretty new to using Capistrano (but pretty addicted already) >>> so I >>> apologize in advance if this topic has been answered many times >>> already. >>> >>> I am trying to get our company to start using Ruby. One of the >>> components I am trying to replace is cfengine. I think that >>> Capistrano >>> would be much more powerful, simple and easy to maintain (we are >>> only >>> using cfengine for deploying our application). >>> >>> One of the typical tasks we do is to check if one of our package is >>> installed (a rpm for instance), and if yes what is its version. >>> Based >>> on the result, we will or not upload the RPM and install/update >>> it. We >>> don't want to do it no matter what, there can be a lot of >>> packages to >>> potentially install on 20 servers. >>> >>>> From what I understand of Capistrano philosophy, a command can be >>> executed on a list of servers determined by their roles and >>> optionally >>> additional attributes. I didn't find a way to limit a >>> run/stream/sudo/put/delete command to a list of servers built at >>> runtime. >>> >>> So I have written a patch (http://dev.rubyonrails.org/ticket/7223: >>> Allow to set environment variables and limit the list of servers >>> when >>> running a remote command) to do just that (it also allow to set >>> environment variables). Is there an easier built-in way to do >>> that? If >>> not, do you think it is the right way to implement it? >>> >>> Thanks, >>> >>> --mathieul >>> >>> >>>> >> >> >>> > > > > --~--~---------~--~----~------------~-------~--~----~ To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/capistrano -~----------~----~----~----~------~----~------~--~---
