Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No idea what *something* is!" after running fabric2 #1854

Open
ajmcateer opened this Issue Aug 16, 2018 · 11 comments

Comments

Projects
None yet
6 participants
@ajmcateer
Copy link

commented Aug 16, 2018

I am new to fabric and having trouble getting it to work. I installed it via pip3 first when I tried to run it I was getting Command 'fab' not found, I eventually found it in /home/me/.local/bin/fab2.

Is this the correct place?

Second whenever I run it like so

/home/me/.local/bin/fab2 version

I get

(2, 3, 1)
2.3.1
No idea what 'version' is!
import fabric
if hasattr(fabric, '__version__'):
    # For fabric2
    print(fabric.__version_info__)
    print(fabric.__version__)   # for a version tuple
else:
    # for fabric1
    from fabric.api import *
    print(env.version)

Is /home/me/.local/bin/fab2 the correct location?
What is 'No idea what 'version' is!' why does it show up?

@ploxiln

This comment has been minimized.

Copy link

commented Aug 16, 2018

It's looking for a task function named "version" in a fabfile and not finding one. fab --version does what you want there.

$HOME/.local/bin/ is where pip installs executable "entrypoints" when you pip install --user ... - you could add $HOME/.local/bin to your PATH (e.g. in your ~/.bash_profile or ~/.bashrc). If you did sudo pip install Fabric (without --user) it would put the executable entrypoint in /usr/local/bin/ which is probably in your PATH already. Or you can probably python -m fabric <fab args> instead.

@ajmcateer

This comment has been minimized.

Copy link
Author

commented Aug 16, 2018

Hi thank you fabric --version worked great

I changed the script to look like this

def hello():
    print("Hello world!")

I am still getting 'No idea what 'hello' is!'

Is there a tutorial for fabric 2 I am having a hell of a time getting anything to work in it. I found the tutorial for fabric 1.14 but that isn't really helpful at the moment since none of the imports work. I am assuming fabric 2 handles it differently.

if I run with fab or fab2 I get the same error

I have fabric in /home/me/fabric

@standaloneSA

This comment has been minimized.

Copy link

commented Aug 21, 2018

@ajmcateer, I had this problem as well. The issue is that thew new fabric task method (as discussed here - http://docs.fabfile.org/en/1.14/usage/tasks.html) is to use the @task decorator. The equivalent "Hello World' example is:

from fabric import task

@task
def hello(ctx):
  print("Hello World")

Running 'fab hello' yields the expected output.

@mandarvaze

This comment has been minimized.

Copy link

commented Oct 13, 2018

I have both from fabric import task as well as @task decorator.
Still I'm getting 'No idea ..' error.

Additional details :

$ fab --version 
Fabric 2.3.1
Paramiko 2.4.1
Invoke 1.1.1

$ python --version
Python 3.6.2

$ more tasks.py
#!/usr/bin/env python

from fabric import task

@task
def build(c):
    import pdb; pdb.set_trace()
    print("Building!")

$ fab build -f tasks.py
No idea what 'build' is!
@gpwalczak

This comment has been minimized.

Copy link

commented Oct 14, 2018

@mandravaze, I can confirm it worked for me, though I have task in fabfile.py (it think this is the problem in your env) and I use following line to call
$fab build

@mandarvaze

This comment has been minimized.

Copy link

commented Oct 15, 2018

it think this is the problem in your env

How I can troubleshoot ? What additional data would you like ?

@gpwalczak

This comment has been minimized.

Copy link

commented Oct 15, 2018

What files do you have in this location? I think build() should be in the fabfile.py, if it is there, perhaps your fab picks up wrong file...

@ploxiln

This comment has been minimized.

Copy link

commented Oct 15, 2018

@mandarvaze in your command fab build -f tasks.py there are multiple confusions.

  • arguments for fab itself must come before the first taskname, like fab -f tasks.py build
  • the -f flag is for a config file, not for a tasks collection, that's the -cflag, like fab -c tasks build (no ".py" extension!)
  • For inv (invoke), if the file with the tasks is tasks.py in the current directory, you don't need to specify it. For fab (fabric), if the file with the tasks is fabfile.py in the current directory, you don't need to specify it.
@mandarvaze

This comment has been minimized.

Copy link

commented Oct 15, 2018

@ploxiln fab -c tasks build works. 👍
Thanks.

@simonzen

This comment has been minimized.

Copy link

commented Mar 20, 2019

@ajmcateer, I had this problem as well. The issue is that thew new fabric task method (as discussed here - http://docs.fabfile.org/en/1.14/usage/tasks.html) is to use the @task decorator. The equivalent "Hello World' example is:

from fabric import task

@task
def hello(ctx):
  print("Hello World")

Running 'fab hello' yields the expected output.

sorry for stupid question, but why do we need 'ctx' arg? what is it?

@ploxiln

This comment has been minimized.

Copy link

commented Mar 20, 2019

in fabric 2 you need this ctx to actually run commands on the correct system, e.g. ctx.run("hostname")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.