Discussion:
[Fab-user] (no subject)
Ajay Jain
2016-07-04 10:32:29 UTC
Permalink
I want a help regarding fabric. I have defined *env.hosts* in a function
let say *set_host()* and I call *set_hosts()* function in my another
function let say *task()* which have some *run* commands. So every time why
it asks for host string when I run "*fab task*". but when I call "*fab
set_host task*" it doesnt ask for *host string.*

so how would I define my env.hosts so that it will not ask me for host
string. I am giving hosts info from configuration file.
Brandon Whaley
2016-07-04 20:02:40 UTC
Permalink
I've found that it's best not to set env.hosts in code but instead to
define roles based on your config file and use the fab tool to specify a
role. Here's an example:

====
my_roles.json
====
{
"web": [ "***@web1.example.com", "***@web2.example.com" ],
"db": [ "***@db1.example.com", "***@db2.example.com" ]
}

====
fabfile.py
====
from fabric.api import env, run, task
import json

def load_roles():
with open('my_roles.json') as f:
env.roledefs = json.load(f)

load_roles()

@task
def my_task():
run("hostname")

====
CLI
====
fab -R web my_task

# output from running "my_task" for each of web1 and web2 is here
Post by Ajay Jain
I want a help regarding fabric. I have defined *env.hosts* in a function
let say *set_host()* and I call *set_hosts()* function in my another
function let say *task()* which have some *run* commands. So every time
why it asks for host string when I run "*fab task*". but when I call "*fab
set_host task*" it doesnt ask for *host string.*
so how would I define my env.hosts so that it will not ask me for host
string. I am giving hosts info from configuration file.
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Loading...