Discussion:
[Fab-user] problem with host_string/hosts (no hosts found)
Wawrzek Niewodniczanski
2014-10-03 09:37:08 UTC
Permalink
Hi,

For quite a long time I've been using various fabric based scripts.
Recently I hit very strange problem. Following short script
illustrates my issue.


#!/usr/bin/env python

import fabric
from fabric.api import env, run

env.hosts = ['localhost']

def test():
print "Hosts:", env['hosts']
print "Host_string", env['host_string']
run('uname -a')


test()


And when I run It I got:

#>./fabric-min.py
Hosts: ['localhost']
Host_string None
No hosts found. Please specify (single) host string for connection: localhost
[localhost] run: uname -a


I copied content to fabfile.py and got the same:

#>fab test
Hosts: ['localhost']
Host_string None
No hosts found. Please specify (single) host string for connection: ^C
Stopped.

What do I do wrong?


I run my tests at Ubuntu 14.04 LTS with
Python 2.7.6
Fabric 1.8.2
Paramiko 1.10.1


Thanks,
Wawrzek
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: ***@wawrzek.name
Linux User #177124
Carlos García
2014-10-03 10:00:53 UTC
Permalink
Hi Wawrzek,

if you need to specify a host per task, I would recommend you to use the
@hosts decorator:

@hosts('localhost)
def test():
print "Hosts:", env['hosts']
print "Host_string", env['host_string']
run('uname -a')


Anyway, check out the documentation at
http://docs.fabfile.org/en/latest/usage/execution.html#how-host-lists-are-constructed
It explains how the hosts lists are constructed and how can you use it. I
usually use the -H flag in the fab command.

Regards
Post by Wawrzek Niewodniczanski
Hi,
For quite a long time I've been using various fabric based scripts.
Recently I hit very strange problem. Following short script
illustrates my issue.
#!/usr/bin/env python
import fabric
from fabric.api import env, run
env.hosts = ['localhost']
print "Hosts:", env['hosts']
print "Host_string", env['host_string']
run('uname -a')
test()
#>./fabric-min.py
Hosts: ['localhost']
Host_string None
No hosts found. Please specify (single) host string for connection: localhost
[localhost] run: uname -a
#>fab test
Hosts: ['localhost']
Host_string None
No hosts found. Please specify (single) host string for connection: ^C
Stopped.
What do I do wrong?
I run my tests at Ubuntu 14.04 LTS with
Python 2.7.6
Fabric 1.8.2
Paramiko 1.10.1
Thanks,
Wawrzek
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
Linux User #177124
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
--
Carlos García
Director de Operaciones
Tel. 695 624 167 - 902 620 100
www.stoneworksolutions.net

AVISO DE CONFIDENCIALIDAD
Tanto este mensaje como todos los posibles documentos adjuntos al mismo son
confidenciales y están dirigidos exclusivamente a los destinatarios de los
mismos. Por favor, si Ud no es uno de dichos destinatarios, notifíquenos
este hecho y elimine el mensaje de su sistema. Queda prohibida la copia,
difusión o revelación de su contenido a terceros sin el previo
consentimiento por escrito del remitente. En caso contrario, vulnerarán la
legislación vigente
Wawrzek Niewodniczanski
2014-10-03 10:19:55 UTC
Permalink
Post by Carlos García
Hi Wawrzek,
Hello Carlos,
Post by Carlos García
if you need to specify a host per task, I would recommend you to use the
I have a list for many hosts, but choose to present an example with
'localhost' because it works everywhere.
Post by Carlos García
@hosts('localhost')
print "Hosts:", env['hosts']
print "Host_string", env['host_string']
run('uname -a')
Thanks for suggestion - it does neither work. I'm not surprise - 'hosts' is
not a problem. It is set up correctly, but somehow host_string ins not
properly set up for a function.
Post by Carlos García
Anyway, check out the documentation at
http://docs.fabfile.org/en/latest/usage/execution.html#how-host-lists-are-constructed
It explains how the hosts lists are constructed and how can you use it. I
usually use the -H flag in the fab command.
Based on documentation (which I've been molesting since I hit a problem)
somehow fabric doesn't properly iterate over env.hosts. Maybe I have a take
a look into sources.

Thanks,
Wawrzek
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: ***@wawrzek.name
Linux User #177124
Wawrzek Niewodniczanski
2014-10-03 11:20:39 UTC
Permalink
Hi,

Very interesting update.

To add mister when I run script from ipython (%run fabfile.py) it's
behaves properly.


Thanks,
Wawrzek
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: ***@wawrzek.name
Linux User #177124
Wawrzek Niewodniczanski
2014-10-03 12:04:48 UTC
Permalink
On 3 October 2014 11:19, Wawrzek Niewodniczanski <***@wawrzek.name> wrote:

[...]
Maybe I have a take a look into sources.
I look into source code and it seems that problem might be with 'all_hosts'
in tasks.py I see following lines:

# Call on host list
if my_env['all_hosts']:
# Attempt to cycle on hosts, skipping if needed
for host in my_env['all_hosts']:


Wawrzek
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: ***@wawrzek.name
Linux User #177124
Wawrzek Niewodniczanski
2014-10-03 12:32:58 UTC
Permalink
Hi,

Based on page [1]

#!/usr/bin/env python

import fabric
from fabric.api import env, run, settings

env.hosts = ['localhost']


def test():
for host in env.hosts:
with settings(host_string=host):
run('uname -a')

test()

Now it works. Not exactly what I wanted, but it can give me new possibilities.

Wawrzek

[1] http://stackoverflow.com/questions/6741523/using-python-fabric-without-the-command-line-tool-fab
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: ***@wawrzek.name
Linux User #177124
Wawrzek Niewodniczanski
2014-11-20 21:11:52 UTC
Permalink
Post by Wawrzek Niewodniczanski
Hi,
For quite a long time I've been using various fabric based scripts.
Recently I hit very strange problem. Following short script
illustrates my issue.
#!/usr/bin/env python
import fabric
from fabric.api import env, run
env.hosts = ['localhost']
print "Hosts:", env['hosts']
print "Host_string", env['host_string']
run('uname -a')
test()
I found the bug.
The line:
test()

should be:
execute(test)

and everything is fine!!!

Cheers.
Wawrzek
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: ***@wawrzek.name
Linux User #177124
Loading...