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.
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'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With