Discussion:
[Fab-user] No hosts found - Fabric execution model: works only on relative imports?
Alec Taylor
2016-01-27 05:21:13 UTC
Permalink
Using Fabric outside a fabfile. `fabric.api.execute` on relative imported
functions works.

Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"

To illustrate, this works:

## foo/__init__.py

from fabric.api import execute
from bar import funtimes

domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]

execute(funtimes)

## foo/bar.py

from fabric.api import run

def funtimes(): run('hello funtimes')

Whilst this fails:

## foo/__init__.py

from fabric.api import execute
from can.haz import funtimes

domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]

execute(funtimes)

## can/haz.py

from fabric.api import run

def funtimes(): run('hello funtimes')

# also tried
def funtimes2(env):
fabric.api.env = env
run('hello funtimes2')
Carlos García
2016-01-27 08:15:43 UTC
Permalink
Hi Alec,

the examples given doesn’t work. Maybe you’re missing something.

env should be imported from fabric.api, if not, Python fails with NameError:
name 'env' is not defined

Also, the Python path should include foo/and can/, so you need to call a
python executable from the project root (Or add ROOT_DIRECTORY to the
python path with sys.path.append(ROOT_DIRECTORY)). For example:

## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes

domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]

execute(funtimes)

And you execute it with: python foo/__init__.py. And this works.


Regards

2016-01-27 6:21 GMT+01:00 Alec Taylor <***@gmail.com>:

Using Fabric outside a fabfile. `fabric.api.execute` on relative imported
Post by Alec Taylor
functions works.
Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"
## foo/__init__.py
from fabric.api import execute
from bar import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## foo/bar.py
from fabric.api import run
def funtimes(): run('hello funtimes')
## foo/__init__.py
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## can/haz.py
from fabric.api import run
def funtimes(): run('hello funtimes')
# also tried
fabric.api.env = env
run('hello funtimes2')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
​
--
Alec Taylor
2016-02-03 12:37:47 UTC
Permalink
Hmm, I can't seem to confirm the issue in a test case. How is your solution
working without importing `env`? - Also, should I import `env` from slave?
- I tried setting the two `env`s to equal, but it still prompted me for
host (yes, env.hosts is definitely set when it reaches slave)

/tmp/pyttt$ tree
.
├── master
│ ├── master
│ │ └── __init__.py
│ └── setup.py
└── slave
├── setup.py
└── slave
└── __init__.py

4 directories, 4 files


*master/__init__.py*

#!/usr/bin/env python

from os import environ

from fabric.api import execute, env

from slave import funtimes

env.key_filename = environ['PRIVATE_QUAY_PATH']
env.hosts = ['ec2-{omitted}.compute.amazonaws.com']
env.user = 'ubuntu'

execute(funtimes)


*slave/__init__.py*

#!/usr/bin/env python

from fabric.api import run

def funtimes():
run('echo Hello funtimes')


On Wed, Jan 27, 2016 at 7:15 PM, Carlos García <
Post by Carlos García
Hi Alec,
the examples given doesn’t work. Maybe you’re missing something.
name 'env' is not defined
Also, the Python path should include foo/and can/, so you need to call a
python executable from the project root (Or add ROOT_DIRECTORY to the
## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
And you execute it with: python foo/__init__.py. And this works.
Regards
Using Fabric outside a fabfile. `fabric.api.execute` on relative imported
Post by Alec Taylor
functions works.
Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"
## foo/__init__.py
from fabric.api import execute
from bar import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## foo/bar.py
from fabric.api import run
def funtimes(): run('hello funtimes')
## foo/__init__.py
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## can/haz.py
from fabric.api import run
def funtimes(): run('hello funtimes')
# also tried
fabric.api.env = env
run('hello funtimes2')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
​
--
Carlos García
2016-02-03 12:59:40 UTC
Permalink
Yeah, env must be imported to work.

In your code, probably execute is not using env.hosts for any reason. Try
to pass hosts as parameter to execute():

execute(funtimes, hosts = ['ec2-{omitted}.compute.amazonaws.com'])

Let me know if this works. I can’t test by myself right now.

Regards

2016-02-03 13:37 GMT+01:00 Alec Taylor <***@gmail.com>:

Hmm, I can't seem to confirm the issue in a test case. How is your solution
Post by Alec Taylor
working without importing `env`? - Also, should I import `env` from slave?
- I tried setting the two `env`s to equal, but it still prompted me for
host (yes, env.hosts is definitely set when it reaches slave)
/tmp/pyttt$ tree
.
├── master
│ ├── master
│ │ └── __init__.py
│ └── setup.py
└── slave
├── setup.py
└── slave
└── __init__.py
4 directories, 4 files
*master/__init__.py*
#!/usr/bin/env python
from os import environ
from fabric.api import execute, env
from slave import funtimes
env.key_filename = environ['PRIVATE_QUAY_PATH']
env.hosts = ['ec2-{omitted}.compute.amazonaws.com']
env.user = 'ubuntu'
execute(funtimes)
*slave/__init__.py*
#!/usr/bin/env python
from fabric.api import run
run('echo Hello funtimes')
On Wed, Jan 27, 2016 at 7:15 PM, Carlos García <
Post by Carlos García
Hi Alec,
the examples given doesn’t work. Maybe you’re missing something.
name 'env' is not defined
Also, the Python path should include foo/and can/, so you need to call a
python executable from the project root (Or add ROOT_DIRECTORY to the
## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
And you execute it with: python foo/__init__.py. And this works.
Regards
Using Fabric outside a fabfile. `fabric.api.execute` on relative imported
Post by Alec Taylor
functions works.
Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"
## foo/__init__.py
from fabric.api import execute
from bar import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## foo/bar.py
from fabric.api import run
def funtimes(): run('hello funtimes')
## foo/__init__.py
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## can/haz.py
from fabric.api import run
def funtimes(): run('hello funtimes')
# also tried
fabric.api.env = env
run('hello funtimes2')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
​
--
​
Alec Taylor
2016-02-03 13:44:05 UTC
Permalink
Nope, that didn't work. Also tried adding `print` statements throughout
fabric/tasks.py, but they don't show up.

I've added one to WrappedCallableTask._execute and another two to `execute`.

Even tried uninstalling fabric, editing a cloned version, then installing
that. Same lack of debug messages. Also tried outputting to a /tmp file, in
case of conflict. Same lack of information.

Not sure why this isn't working

On Wed, Feb 3, 2016 at 11:59 PM, Carlos García <
Post by Carlos García
Yeah, env must be imported to work.
In your code, probably execute is not using env.hosts for any reason. Try
execute(funtimes, hosts = ['ec2-{omitted}.compute.amazonaws.com'])
Let me know if this works. I can’t test by myself right now.
Regards
Hmm, I can't seem to confirm the issue in a test case. How is your
solution working without importing `env`? - Also, should I import `env`
from slave? - I tried setting the two `env`s to equal, but it still
prompted me for host (yes, env.hosts is definitely set when it reaches
slave)
/tmp/pyttt$ tree
.
├── master
│ ├── master
│ │ └── __init__.py
│ └── setup.py
└── slave
├── setup.py
└── slave
└── __init__.py
4 directories, 4 files
*master/__init__.py*
#!/usr/bin/env python
from os import environ
from fabric.api import execute, env
from slave import funtimes
env.key_filename = environ['PRIVATE_QUAY_PATH']
env.hosts = ['ec2-{omitted}.compute.amazonaws.com']
env.user = 'ubuntu'
execute(funtimes)
*slave/__init__.py*
#!/usr/bin/env python
from fabric.api import run
run('echo Hello funtimes')
On Wed, Jan 27, 2016 at 7:15 PM, Carlos García <
Post by Carlos García
Hi Alec,
the examples given doesn’t work. Maybe you’re missing something.
name 'env' is not defined
Also, the Python path should include foo/and can/, so you need to call
a python executable from the project root (Or add ROOT_DIRECTORY to the
## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
And you execute it with: python foo/__init__.py. And this works.
Regards
Using Fabric outside a fabfile. `fabric.api.execute` on relative
imported functions works.
Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"
## foo/__init__.py
from fabric.api import execute
from bar import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## foo/bar.py
from fabric.api import run
def funtimes(): run('hello funtimes')
## foo/__init__.py
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## can/haz.py
from fabric.api import run
def funtimes(): run('hello funtimes')
# also tried
fabric.api.env = env
run('hello funtimes2')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
​
--
​
Carlos García
2016-02-03 14:02:43 UTC
Permalink
Hi Alec,

I don’t really understand how your example code can work, as the import
slave canÂŽt load slave with that directory layout. It should be import
slave.slave, but the parent directory lacks of __init__.py so it’s not
being recognized as a module.

Please, tell me what exactly do you have. Making some changes I’ve managed
to make it work, but I need to know what you have.

Also, how are you executing your scripts?

Regards
​
Post by Alec Taylor
Nope, that didn't work. Also tried adding `print` statements throughout
fabric/tasks.py, but they don't show up.
I've added one to WrappedCallableTask._execute and another two to `execute`.
Even tried uninstalling fabric, editing a cloned version, then installing
that. Same lack of debug messages. Also tried outputting to a /tmp file, in
case of conflict. Same lack of information.
Not sure why this isn't working
On Wed, Feb 3, 2016 at 11:59 PM, Carlos García <
Post by Carlos García
Yeah, env must be imported to work.
In your code, probably execute is not using env.hosts for any reason.
execute(funtimes, hosts = ['ec2-{omitted}.compute.amazonaws.com'])
Let me know if this works. I can’t test by myself right now.
Regards
Hmm, I can't seem to confirm the issue in a test case. How is your
solution working without importing `env`? - Also, should I import `env`
from slave? - I tried setting the two `env`s to equal, but it still
prompted me for host (yes, env.hosts is definitely set when it reaches
slave)
/tmp/pyttt$ tree
.
├── master
│ ├── master
│ │ └── __init__.py
│ └── setup.py
└── slave
├── setup.py
└── slave
└── __init__.py
4 directories, 4 files
*master/__init__.py*
#!/usr/bin/env python
from os import environ
from fabric.api import execute, env
from slave import funtimes
env.key_filename = environ['PRIVATE_QUAY_PATH']
env.hosts = ['ec2-{omitted}.compute.amazonaws.com']
env.user = 'ubuntu'
execute(funtimes)
*slave/__init__.py*
#!/usr/bin/env python
from fabric.api import run
run('echo Hello funtimes')
On Wed, Jan 27, 2016 at 7:15 PM, Carlos García <
Post by Carlos García
Hi Alec,
the examples given doesn’t work. Maybe you’re missing something.
name 'env' is not defined
Also, the Python path should include foo/and can/, so you need to call
a python executable from the project root (Or add ROOT_DIRECTORY to
## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
And you execute it with: python foo/__init__.py. And this works.
Regards
Using Fabric outside a fabfile. `fabric.api.execute` on relative
imported functions works.
Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"
## foo/__init__.py
from fabric.api import execute
from bar import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## foo/bar.py
from fabric.api import run
def funtimes(): run('hello funtimes')
## foo/__init__.py
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## can/haz.py
from fabric.api import run
def funtimes(): run('hello funtimes')
# also tried
fabric.api.env = env
run('hello funtimes2')
_______________________________________________
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
Alec Taylor
2016-02-03 15:06:36 UTC
Permalink
So this works:
https://github.com/AlecTaylor/fabric_test_cases

But I can't figure out why my larger real case fails. The env is set
correctly. I'm running in a virtualenv if that makes a difference.

On Thu, Feb 4, 2016 at 1:02 AM, Carlos García <
Post by Carlos García
Hi Alec,
I don’t really understand how your example code can work, as the import
slave canÂŽt load slave with that directory layout. It should be import
slave.slave, but the parent directory lacks of __init__.py so it’s not
being recognized as a module.
Please, tell me what exactly do you have. Making some changes I’ve managed
to make it work, but I need to know what you have.
Also, how are you executing your scripts?
Regards
​
Post by Alec Taylor
Nope, that didn't work. Also tried adding `print` statements throughout
fabric/tasks.py, but they don't show up.
I've added one to WrappedCallableTask._execute and another two to `execute`.
Even tried uninstalling fabric, editing a cloned version, then installing
that. Same lack of debug messages. Also tried outputting to a /tmp file, in
case of conflict. Same lack of information.
Not sure why this isn't working
On Wed, Feb 3, 2016 at 11:59 PM, Carlos García <
Post by Carlos García
Yeah, env must be imported to work.
In your code, probably execute is not using env.hosts for any reason.
execute(funtimes, hosts = ['ec2-{omitted}.compute.amazonaws.com'])
Let me know if this works. I can’t test by myself right now.
Regards
Hmm, I can't seem to confirm the issue in a test case. How is your
solution working without importing `env`? - Also, should I import `env`
from slave? - I tried setting the two `env`s to equal, but it still
prompted me for host (yes, env.hosts is definitely set when it reaches
slave)
/tmp/pyttt$ tree
.
├── master
│ ├── master
│ │ └── __init__.py
│ └── setup.py
└── slave
├── setup.py
└── slave
└── __init__.py
4 directories, 4 files
*master/__init__.py*
#!/usr/bin/env python
from os import environ
from fabric.api import execute, env
from slave import funtimes
env.key_filename = environ['PRIVATE_QUAY_PATH']
env.hosts = ['ec2-{omitted}.compute.amazonaws.com']
env.user = 'ubuntu'
execute(funtimes)
*slave/__init__.py*
#!/usr/bin/env python
from fabric.api import run
run('echo Hello funtimes')
On Wed, Jan 27, 2016 at 7:15 PM, Carlos García <
Post by Carlos García
Hi Alec,
the examples given doesn’t work. Maybe you’re missing something.
name 'env' is not defined
Also, the Python path should include foo/and can/, so you need to
call a python executable from the project root (Or add ROOT_DIRECTORY
## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
And you execute it with: python foo/__init__.py. And this works.
Regards
Using Fabric outside a fabfile. `fabric.api.execute` on relative
imported functions works.
Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"
## foo/__init__.py
from fabric.api import execute
from bar import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## foo/bar.py
from fabric.api import run
def funtimes(): run('hello funtimes')
## foo/__init__.py
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## can/haz.py
from fabric.api import run
def funtimes(): run('hello funtimes')
# also tried
fabric.api.env = env
run('hello funtimes2')
_______________________________________________
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
Alec Taylor
2016-02-05 06:31:03 UTC
Permalink
Extending my test case to try and figure out where I've convoluted, and
realised my mistake



was calling `execute(funtimes(*args, **kwargs))` rather than
`execute(funtimes,
*args, **kwargs)`
Post by Alec Taylor
.<
https://github.com/AlecTaylor/fabric_test_cases
But I can't figure out why my larger real case fails. The env is set
correctly. I'm running in a virtualenv if that makes a difference.
On Thu, Feb 4, 2016 at 1:02 AM, Carlos García <
Post by Carlos García
Hi Alec,
I don’t really understand how your example code can work, as the import
slave canÂŽt load slave with that directory layout. It should be import
slave.slave, but the parent directory lacks of __init__.py so it’s not
being recognized as a module.
Please, tell me what exactly do you have. Making some changes I’ve
managed to make it work, but I need to know what you have.
Also, how are you executing your scripts?
Regards
​
Post by Alec Taylor
Nope, that didn't work. Also tried adding `print` statements throughout
fabric/tasks.py, but they don't show up.
I've added one to WrappedCallableTask._execute and another two to `execute`.
Even tried uninstalling fabric, editing a cloned version, then
installing that. Same lack of debug messages. Also tried outputting to a
/tmp file, in case of conflict. Same lack of information.
Not sure why this isn't working
On Wed, Feb 3, 2016 at 11:59 PM, Carlos García <
Post by Carlos García
Yeah, env must be imported to work.
In your code, probably execute is not using env.hosts for any reason.
execute(funtimes, hosts = ['ec2-{omitted}.compute.amazonaws.com'])
Let me know if this works. I can’t test by myself right now.
Regards
Hmm, I can't seem to confirm the issue in a test case. How is your
solution working without importing `env`? - Also, should I import `env`
from slave? - I tried setting the two `env`s to equal, but it still
prompted me for host (yes, env.hosts is definitely set when it reaches
slave)
/tmp/pyttt$ tree
.
├── master
│ ├── master
│ │ └── __init__.py
│ └── setup.py
└── slave
├── setup.py
└── slave
└── __init__.py
4 directories, 4 files
*master/__init__.py*
#!/usr/bin/env python
from os import environ
from fabric.api import execute, env
from slave import funtimes
env.key_filename = environ['PRIVATE_QUAY_PATH']
env.hosts = ['ec2-{omitted}.compute.amazonaws.com']
env.user = 'ubuntu'
execute(funtimes)
*slave/__init__.py*
#!/usr/bin/env python
from fabric.api import run
run('echo Hello funtimes')
On Wed, Jan 27, 2016 at 7:15 PM, Carlos García <
Post by Carlos García
Hi Alec,
the examples given doesn’t work. Maybe you’re missing something.
name 'env' is not defined
Also, the Python path should include foo/and can/, so you need to
call a python executable from the project root (Or add ROOT_DIRECTORY
## foo/__init__.py
import sys
import os
sys.path.append(os.path.abspath('.'))
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
And you execute it with: python foo/__init__.py. And this works.
Regards
Using Fabric outside a fabfile. `fabric.api.execute` on relative
imported functions works.
Importing other installed modules fails with "No hosts found. Please
specify (single) host string for connection:"
## foo/__init__.py
from fabric.api import execute
from bar import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## foo/bar.py
from fabric.api import run
def funtimes(): run('hello funtimes')
## foo/__init__.py
from fabric.api import execute
from can.haz import funtimes
domain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]
execute(funtimes)
## can/haz.py
from fabric.api import run
def funtimes(): run('hello funtimes')
# also tried
fabric.api.env = env
run('hello funtimes2')
_______________________________________________
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
Loading...