No hosts found: Fabric

bonzi picture bonzi · Apr 3, 2011 · Viewed 15.3k times · Source

when I run my python code it is asking for host.

No hosts found. Please specify (single) host string for connection:

I have the following code:

from fabric.api import *
from fabric.contrib.console import confirm

env.hosts = [ 'ipaddress' ]

def remoteRun():
    print "ENV %s" %(env.hosts)
    out = run('uname -r')
    print "Output %s"%(out)

remoteRun();

I even tried running fab with -H option and I am getting the same message. I'm using Ubuntu 10.10 any help is appreciated. Btw I am a newbie in Python.

Answer

Gringo Suave picture Gringo Suave · Aug 19, 2012

In order to get hosts to work in a script outside of the fab command-line tool and fabfile.py, you'll have to use execute():

from fabric.api import run
from fabric.tasks import execute

def mytask():
    run('uname -a')

results = execute(mytask)