Martian Puss
Martian Puss

Reputation: 720

How to specify env.shell while in fabric.operations.execute

I am using fabric.tasks.execute to execute commands on remote servers, and need to use different shell depending on system. now my code is like:

def run_test(server_ip, server_shell):
    execute(test,server_ip,server_shell,host=server_ip) # host can be specified in execute argument

def test(ip,shell):
    env.shell=shell
    run('command')

I can live with this but prefer execute specifing env.shell the command will use instead of assigning it within the task, that's just simple and clean. Can i use something like:

def run_test(server_ip, server_shell):
    execute(test,server_ip,server_shell,host=server_ip,*shell=server_shell*) # host can be specified in execute argument

def test(ip,shell):
    run('command')

Upvotes: 0

Views: 333

Answers (1)

jfs
jfs

Reputation: 414149

execute() docs say that only host, hosts, role, roles and exclude_hosts keyword parameters are special; the rest is passed to the task as is i.e., shell is passed to test():

def test(shell):
    with settings(shell=shell):
        run('command')

execute(test, shell=server_shell, host=server_ip)

Upvotes: 1

Related Questions