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

env.host not set #690

Closed
offlinehacker opened this issue Jul 21, 2012 · 5 comments
Closed

env.host not set #690

offlinehacker opened this issue Jul 21, 2012 · 5 comments

Comments

@offlinehacker
Copy link

Env.host not set when fabfile called using fab without env.hosts specified in fab file.

@offlinehacker
Copy link
Author

To be more speciffic, when fab asks me(in runtime) for hosts to run actions on env.host is not set

@bitprophet
Copy link
Member

Sounds like a bug, I can't think of a reason why it shouldn't fill out env.host (what that runtime prompt does definitely fill out is env.host_string). Will take a look, thanks!

@bitprophet
Copy link
Member

I can't replicate this (but I did write a new test for it! yay!). See upcoming commit notice.

Basically, what I did was ensure that after a run() call triggers the "I have no host list" prompt, env.host_string and env.host are both filled in correctly. This does work correctly for me, as of Fab 1.3.x release branch.

If you could, please:

  • Make sure you're on a relatively recent version, e.g. Fab 1.3.8 or 1.4.3
  • Confirm that the problem still exists for your use case
  • Give details about how to replicate it, i.e. your fabfile code & a paste of your shell session when you run the code & get the unexpected behavior.

I'll close the ticket for now as "can't reproduce" but I think you can reopen it when you comment (and if not obviously I will reopen it when you do!)

Thanks a lot!

@offlinehacker
Copy link
Author

Okay here is a way to reproduce and i found it not may be a bug, but just the way how fabric works:

from fabric.api import env, task, run

@task
def test_task():
    print env.host
    run("ls")

Now run in the following way: fab test_task

It looks like that hosts prompt gets displayed when first command is executed on remote server and it makes sense(since fabric can execute command also locally), but is there any way(decorator option) to require fabric to have host set even before first command is executed(i know that i can make something like run("exit 0") to issue connection)?

Thanks!

@bitprophet
Copy link
Member

Ah, yes -- that's how Fabric has to work to allow local-only tasks to operate correct (docs).

Depending on why you want the host set non-lazily, you might find the require() operation useful, which will cause things to bail out with a helpful-ish "where's my ?" message.

Or you can use abort-on-prompts (it's a config setting and a CLI flag) which is similar but more rigorous, it will cause an abort for any prompt. This is good if your real problem is trying to run something unattended and you want to prevent fabric from hanging around waiting for input.

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants