|
From: | Alec Taylor |
Subject: | Re: [Fab-user] No hosts found - Fabric execution model: works only on relative imports? |
Date: | Thu, 4 Feb 2016 00:44:05 +1100 |
Yeah,
env
must be imported to work.In your code, probably
execute
is not usingenv.hosts
for any reason. Try to passhosts
as parameter toexecute()
: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 <address@hidden>:
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__.py4 directories, 4 filesmaster/__init__.py#!/usr/bin/env pythonfrom os import environfrom fabric.api import execute, envfrom slave import funtimesenv.key_filename = environ['PRIVATE_QUAY_PATH']env.hosts = ['ec2-{omitted}.compute.amazonaws.com']env.user = 'ubuntu'execute(funtimes)slave/__init__.py#!/usr/bin/env pythonfrom fabric.api import rundef funtimes():run('echo Hello funtimes')On Wed, Jan 27, 2016 at 7:15 PM, Carlos García <address@hidden> wrote:Hi Alec,
the examples given doesn’t work. Maybe you’re missing something.
env
should be imported fromfabric.api
, if not, Python fails withNameError: name 'env' is not defined
Also, the Python path should include
foo/
andcan/
, so you need to call a python executable from the project root (Or addROOT_DIRECTORY
to the python path withsys.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 <address@hidden>:
_______________________________________________Whilst this fails:Using Fabric outside a fabfile. `fabric.api.execute` on relative imported functions works.To illustrate, this works:
Importing other installed modules fails with "No hosts found. Please specify (single) host string for connection:"## foo/__init__.pyfrom fabric.api import executefrom bar import funtimesdomain = 'localhost'
env.user = 'bar'
env.password = 'foo'
env.hosts = [domain]execute(funtimes)
## foo/bar.py
from fabric.api import rundef funtimes(): run('hello funtimes')## foo/__init__.pyfrom fabric.api import executefrom 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 = envrun('hello funtimes2')
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user
--
[Prev in Thread] | Current Thread | [Next in Thread] |