Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:07:23+00:00 2026-05-29T08:07:23+00:00

from fabric.api import env, sudo def get_hostname(): env.hosts = [‘user@host_ip’] env.passwords = {‘user@host_ip’: ‘password’}

  • 0
from fabric.api import env, sudo
def get_hostname():
    env.hosts = ['user@host_ip']
    env.passwords = {'user@host_ip': 'password'}
    hostname = run_cmd('hostname')
    print hostname


def run_cmd(cmd):
    return sudo(cmd)


if __name__ == '__main__':
    get_hostname()

This code is not working it is saying:

No hosts found. Please specify (single) host string for connection:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:07:24+00:00Added an answer on May 29, 2026 at 8:07 am

    The function get_hostname will not be called unless you specify it in the fab arguments, calling it under if __name__ == '__main__' will not do what you think it does because a fabfile is not like a usual python script.

    What you have to do is call your fabfile like this: fab get_hostname run_cmd and to have a more consistent error you can use require function like this:

    from fabric.api import require
    
    
    def run_cmd():
        require('hosts', provided_by=[get_hostname])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Giving the following fabfile: from fabric.api import env, run env.user = 'implicit_user' env.hosts =
I have the following fabfile.py: from fabric.api import env, run host1 = '192.168.200.181' host2
The code I'm trying to run: from fabric.api import * from fabric.contrib.files import *
Fabric displays Disconnecting from username@server... done. for almost 2 minutes prior to showing a
How can I pass a parameter to a fabric task when calling fab from
I have a fabric task set up like this: @task def cli(): command =
In Fabric, when I try to use any alias' or functions from my .bash_profile
I'm re-writing a website from the ground up for azure. Each user has ownership
I would like to create env variables once to use elsewhere in my fabric
I want to use Fabric.api.run to directly start an application in a remote box.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.