Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fabric env.hosts and run in the same method => No hosts found

Why:

from fabric.api import env, run

def update():
    env.hosts = ['apycat']
    run('cd /var/www/menu; svn up')

does not work when I fab update, while:

from fabric.api import env, run

env.hosts = ['apycat']

def update():
    run('cd /var/www/menu; svn up')

does?

Didn't find anything about this in the docs.

like image 282
Jill-Jênn Vie Avatar asked Jul 22 '12 18:07

Jill-Jênn Vie


1 Answers

Specifying the host list after the fab command has already made the host list for the fab task will not work. So for the first example you have the update task doesn't have a host list set, to then allow the following run() to operate over. A good section in the docs for this is here.

But it shuold also be noted you can get a use case like the first to work in one of two way. First being with the settings() context manager:

def foo():
    with settings(host_string='apycat'):
        run(...)

The other being with the newer api function execute():

def bar():
    run(...)

def foo():
    execute(bar, hosts=['apycat'])
like image 194
Morgan Avatar answered Nov 03 '22 09:11

Morgan