Fabric: configuring hosts in v2

Created on 14 May 2018  ·  4Comments  ·  Source: fabric/fabric

Hi! Is it possible to specify hosts either in a config file or the fabfile itself?

I know I can provide them via CLI (-H), but if the fabfile is designed to communicate with a specific server, then it just forces the user to do extra stuff for no good reason.

The "best" solution I could figure out was to create the connection by hand, e.g.

@task
def my_ls(c):
    conn = Connection('myhost')
    conn.run('ls')

but that seems quite dirty as I need to (1) duplicate it everywhere and (2) it makes the context argument pointless.

Most helpful comment

Agreed with all above. I really miss the old env.hosts setting. It was beautifully simple.

-1 on needing another config file like invoke.yaml or whatnot. I would much prefer to monkey-patch or some kind of import hook that let me state the hosts.

It also took me a while to figure out that ctx.local is not present if no hosts are specified :(

All 4 comments

I have the same question. I came up with a solution of putting conn = Connection('myhost') at the beginning of the fabfile so it looks like this:

conn = Connection('myhost')

@task
def my_ls(c):
    conn.run('ls')

@task
def my_cd(c):
    conn.run('cd')

....

But I don't like the solution and feel that there should be a way to inject a default connection into the context.

I'd like to know as well. Would be convenient to be able to put hosts in the config file.

Also not providing a host list (with -H) defaults to localhost. I'd like to see an option to prevent this/raise error.

Agreed with all above. I really miss the old env.hosts setting. It was beautifully simple.

-1 on needing another config file like invoke.yaml or whatnot. I would much prefer to monkey-patch or some kind of import hook that let me state the hosts.

It also took me a while to figure out that ctx.local is not present if no hosts are specified :(

See #4!

Was this page helpful?
0 / 5 - 0 ratings