So, the answer was right in the docs. I didn't see it because Google always finds the old version of the docs, I don't know why.
The main issue is indeed with the propagation of the env.hosts
(other env.* values seem to propagate normally.The solution to call a method with an arbitrary list of hosts was of invoking it using execute(<someFunction>, hosts=<someHostList>)
.
For example:
from fabric.api import env, run, execute
def f1():
someList = ['remoteHost1','remoteHost2']
execute(f2, hosts=someList)
def f2():
run('ls /')
To be run with the command: $ fab f1
.
EDIT: updated version