fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fab-user] FAQ on env.cwd ?


From: Chris Steel
Subject: [Fab-user] FAQ on env.cwd ?
Date: Tue, 12 Jul 2011 11:21:32 -0400

Regarding the name env.cwd

If you want to preserve your initial local current working directory in env use a name such as env.local_cwd rather than env.cwd. This is because the value of env.cwd appears to be used by subsequent commands meaning that if you run a remote command on Linux box from a local OS X lsystem, for example and have saved your current working directory using env.cmd then you may find yourself scratching your head at some peculiar error messages.

So this should work just fine in your fabfile:

env.local_cwd  =  os.getcwd()

but this might cause some head scratching at some point in time when executing remote commands:

env.cwd  =  os.getcwd()

def test():
    run('ls -al')

Example Output when run from local OS X host to remote Ubuntu (10.0.1.198)box:

/Users/christophersteel/ontogeny2$ fab remote test
[address@hidden] Executing task 'test'
[address@hidden] run: ls -al
[address@hidden] out: /bin/bash: line 0: cd: /Users/christophersteel/ontogeny2: No such file or directory
[address@hidden] out:

Fatal error: run() encountered an error (return code 1) while executing 'ls -al'



Chris Steel

Fabric rocks. Thank you Jeff!

On Mon, Jul 11, 2011 at 4:35 PM, Jeff Forcier <address@hidden> wrote:
On Mon, Jul 11, 2011 at 10:36 AM, Chris Steel <address@hidden> wrote:
> I want to be able to run a single fab command, for example:
>
>     fab combined_task
>
> so that a number of tasks take place on various target hosts with no
> additional input required.

What you need to do:

* Use host_string instead of hosts. See the docs for a quick
explanation of how/why this works and env.hosts doesn't:
http://docs.fabfile.org/en/1.1.1/usage/library.html#connections
* The gist is that env.hosts only works when set *before* the task is
executed. Either at module level or by a non-remote-executing task run
on the CLI prior, e.g. "fab setup realtask".

What I need to do:

* Add this to the FAQ :)

-Jeff

--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org



--
Christopher Steel

Voice of Access

reply via email to

[Prev in Thread] Current Thread [Next in Thread]