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": [ "[email protected]", "[email protected]" ],
"db": [ "[email protected]", "[email protected]" ]
}
====
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
On Mon, Jul 4, 2016 at 10:34 AM Ajay Jain <[email protected]> wrote:
> 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
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/fab-user
>
_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user