fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] (no subject)


From: Brandon Whaley
Subject: Re: [Fab-user] (no subject)
Date: Mon, 04 Jul 2016 20:02:40 +0000

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": [ "address@hidden", "address@hidden" ],
    "db": [ "address@hidden", "address@hidden" ]
}

====
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 <address@hidden> 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
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user

reply via email to

[Prev in Thread] Current Thread [Next in Thread]